Comments
0
On gorvCode Monk: Dynamic Programming, 11 years ago
+8

Thats the way to go antivenom. Keep coding , Keep learning :)

Is answer for your test case 23 13 (As is provided by my approach)?Also whats the priority criteria to throw away the cheapest item.Please explain.Is position of element used as priority criteria?

My code gives 199 2 as output for this test case.That is as expected to happen.And can you please explain your DP .How you come to it ?

Here is what I did : Suppose I am having a segment tree to update an elemnt and find maximum in a range. cin>>arrLength;

long long  s=0;
for(long long  i=0;i<arrLength;i++){
    cin>>data[i];
    s+=data[i];
}
initSegmentTree();
buildSegmentTree();
long long A=0;
long long B=0;
long long  c=0,j,d=0;
for(long long  i=0;i<arrLength;i+=2){
        for(j=c;j<arrLength;j++){
            if(data[j]!=INT_MIN)
            break; 
        }
        c=j;
        for(j=c+1;j<arrLength;j++){
            if(data[j]!=INT_MIN)
            break;
        }
        if(j>=arrLength)
        {
            A+=data[c];
            break;
        }
        d=j;
        long long  pos = query(c,arrLength-1);
        if(data[pos]-data[c]>data[c]-data[d]){
            A+=data[pos];
            update(pos,INT_MIN);
            update(c,INT_MIN);
            c++;
        }
        else{
            A+=data[c];
            update(c,INT_MIN);
            update(d,INT_MIN);
            c++;
        }
}

How to solve Problem K (Two Pirates)? Why is greedy approach not working for this problem? And what can be perfect approach to solve this question.Any help?

On cgy4everCodeforces Round #228, 12 years ago
0

How comes the Dp relation in Div2 Problem D that dp[v] = sum{dp[t] | dist(1,t) = dist(1,v) — 1}? I am not able to get it. Could someone please explain?

0

rforritz Could u please explain your dp array please.I am not getting reason behind printing out dp[rem] after printing non zero digits.