Comments

can you provide code?

why my above solution is wrong?

what is wrong in it?

static int f(int left,int right,int last,char a[]){
        if(dp[left][right][last]!=null)return dp[left][right][last];
        if(left>=right)return dp[left][right][last]=0;
        if(a[left]!=a[right]){
            return dp[left][right][last]=Math.max(f(left+1,right,last,a),f(left,right-1,last,a));
        }
        else{
            if(last!=a[left]-'a'){
                int temp=2+f(left+1,right-1,a[left]-'a',a);
                temp=Math.max(temp,Math.max(f(left+1,right,last,a),f(left,right-1,last,a)));
                return dp[left][right][last]=temp;
            }
            else{
                return dp[left][right][last]=Math.max(f(left+1,right,last,a),f(left,right-1,last,a));
            }
        }
    }

In problem F Why always take diameter?

please someone explain approach of Div-2 E in easy language?

can some explain what is mean by "minimum expected number of turns" in problem E?

0

please , explain proof.

you can use HashMap in java but it takes O(n*MAX_SUM) and it will time out

public void run() { InputReader sc = new InputReader(System.in); //Scanner sc=new Scanner(System.in); // Random sc=new Random(); PrintWriter out = new PrintWriter(System.out);

int a=sc.nextInt();
    int b=sc.nextInt();
    int n=sc.nextInt();
    long fact[]=new long[1000001];
    fact[0]=1;
    long mod=1000000007;

    for (int i = 1; i <1000001 ; i++) {
        fact[i]=(fact[i-1]*i)%mod;
    }

    long ans=0;
    for (int noOfA = 0; noOfA <=n ; noOfA++) {
        int noOfB=n-noOfA;
        if(check(a*noOfA+b*noOfB,a,b)){
            ans=(ans+(((fact[n]*modInv(fact[noOfA],mod))%mod)*modInv(fact[noOfB],mod))%mod)%mod;
        }
    }

    out.println(ans);

    out.close();
}

boolean check(int n,int a,int b){
    while (n>0){
        if(n%10==a || n%10==b){
            n/=10;
        }
        else{
            return false;
        }
    }
    return true;
}

so,this unique representation comes from greedy approach ?

my solution is as follow --> i have checked if cell(x,y) is '#' or not. if it is, than i have checked for all 8 adjacent direction to it that whether at least one out of 8 it is possible to make 3X3 matrix.if it is than we can fill this cell and ans is YES and it is not possible to make 3X3 matrix than NO.

--> if cell is not '#' than continue.

my solution is . http://codeforces.me/contest/1059/submission/43840425

please anyone explain,in problem c, why this algo. works?

Does cut edge algorithm work for parallel edges?