标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 664 Accepted Submission(s): 394
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 int n,a[24],b[24],dp[24][24][24][24]; 18 int dfs(int fr1,int ta1,int fr2,int ta2,int sum){ 19 if(fr1 > ta1 && fr2 > ta2) return 0; 20 if(dp[fr1][ta1][fr2][ta2]) return dp[fr1][ta1][fr2][ta2]; 21 int theMax = 0; 22 if(fr1 <= ta1){ 23 theMax = max(theMax,sum-dfs(fr1+1,ta1,fr2,ta2,sum-a[fr1])); 24 theMax = max(theMax,sum-dfs(fr1,ta1-1,fr2,ta2,sum-a[ta1])); 25 } 26 if(fr2 <= ta2){ 27 theMax = max(theMax,sum-dfs(fr1,ta1,fr2+1,ta2,sum-b[fr2])); 28 theMax = max(theMax,sum-dfs(fr1,ta1,fr2,ta2-1,sum-b[ta2])); 29 } 30 return dp[fr1][ta1][fr2][ta2] = theMax; 31 } 32 int main() { 33 int t,sum,i; 34 scanf("%d",&t); 35 while(t--){ 36 scanf("%d",&n); 37 for(i = 1; i <= n; i++){ 38 scanf("%d",a+i); 39 sum += a[i]; 40 } 41 for(i = 1; i <= n; i++){ 42 scanf("%d",b+i); 43 sum += b[i]; 44 } 45 memset(dp,0,sizeof(dp)); 46 printf("%d\n",dfs(1,n,1,n,sum)); 47 } 48 return 0; 49 }
hdu 4597 Play Game,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/crackpotisback/p/3927254.html