Skip to content

Instantly share code, notes, and snippets.

@enghqii
Created October 25, 2014 16:54
Show Gist options
  • Save enghqii/054c74732da076fb1d0e to your computer and use it in GitHub Desktop.
Save enghqii/054c74732da076fb1d0e to your computer and use it in GitHub Desktop.
#include <stdio.h>
int max(int a, int b, int c){
int t = ( a > b ? a : b);
return (t > c ? t : c);
}
int max(int a, int b){
return (a > b? a : b);
}
int main(void){
int w[1001]={0,};
int b[1001]={0,};
int dp[1001][16][16]={0,};
int i=1, j, k;
int size=1;
// FILE *in=fopen("input.txt", "r");
while(scanf("%d %d",&w[i],&b[i])!=EOF){
i++; // printf("%d\n", i);
size=i;
}
for(i = 1; i <= size; i++){
for(j = 0; j <= 15; j++){
for(k = 0;k <= 15; k++){
if( j + k > i ){
break;
}
if( j == 0 && k == 0 ){
dp[i][j][k] = 0;
}else if( j == 0 ){
dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j][k-1]+b[i]);
}else if( k == 0 ){
dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j-1][k]+w[i]);
}
else{
dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j-1][k]+w[i], dp[i-1][j][k-1]+b[i]);
}
}
}
}
printf("%d",dp[size][15][15]);
return 0;
}
@enghqii
Copy link
Author

enghqii commented Oct 25, 2014

It may not work. I modified some of code without compiling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment