sicily 1176
2014-10-12 10:16
239 查看
// Problem#: 1176 // Submission#: 2994117 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ // All Copyright reserved by Informatic Lab of Sun Yat-sen University #include<iostream> #include<memory.h> #include<stdio.h> using namespace std; long long int dy[1001][1001]; int c[1001]; long long int score(int a, int b) { long long int temp1,temp2; temp1 = 0; temp2 = 0; if (a == b) { return c[a]; } if(dy[a][b] != -1) { return dy[a][b]; } if(b - a == 1) { return dy[a][b] = c[a] > c[b]? c[a] - c[b]:c[b] - c[a]; } else if ((b - a)%2 == 1) { temp1 = score(a,b-1) + c[b]; temp2 = score(a+1,b) + c[a]; return dy[a][b] = temp1>temp2? temp1:temp2; } else if ((b - a)%2 == 0) { if(c[a] >= c[b]) { return dy[a][b] = score(a+1,b) - c[a]; } else { return dy[a][b] = score(a,b-1) - c[b]; } } } int main() { int n; int time = 0; while(scanf("%d",&n) && n != 0) { memset(c, 0, sizeof (c)); memset(dy, -1, sizeof(dy)); time++; for (int i = 0; i < n; i++) { scanf("%d",&c[i]); } cout<<"In game "<< time <<", the greedy strategy might lose by as many as "<< score(0,n-1) <<" points."<<endl; } }
相关文章推荐
- Sicily 1176. Two Ends
- sicily 1176 (动态规划)
- [Sicily 1176 Two Ends] 动态规划 记忆化搜索
- sicily 1176 Two Ends dp(记忆化搜索)
- Sicily 1176. Two Ends
- sicily 1176 Two Ends
- Sicily1176
- sicily 1176 two ends 动态规划解题
- sicily 1176
- sicily 1176. Two Ends
- sicily 1176 Two ends
- sicily 1176 Two Ends
- sicily 1176. Two Ends (Top-down 动态规划+记忆化搜索 v.s. Bottom-up 动态规划)
- Sicily 1176. Two Ends
- Sicily 1176 Two Ends
- Sicily 1176 Two Ends
- sicily 1176 two ends
- sicily 1176. Two Ends
- [sicily]1176. Two Ends
- Sicily 1176. Two Ends