here is only basic implementation of problems for beginners. If you have any problem with any solution or any basic concept of programming or you want more efficient solution you can mail me.
my suggestion is not to copy and paste codes from here try to understand the logic and think why you were not able to solve it.

Monday, 22 September 2014

Spoj princes farida

// http://www.spoj.com/problems/FARIDA/

#include <stdio.h>
unsigned long long int dp[1010];
int t,n;
unsigned long long int max(unsigned long long int a, unsigned long long int b){
return a > b ? a : b;
}
int main(){
int i, h;
scanf("%d", &t);
for(h=1;h<=t;h++){
scanf("%d",&n);
for(i=0;i<n;i++){
int k;
scanf("%d",&k);
dp[i]=max(k+(i>1?dp[i-2]:0),i>0?dp[i-1]:0);
}
printf("Case %d: %llu\n", h, dp[n-1]);
}

return 0;
}

No comments:

Post a Comment