[动态规划] Sum游戏 ( Game of Sum, Uva 10891 )
来源:互联网 发布:网络交往具有什么特点 编辑:程序博客网 时间:2024/05/20 20:04
抓住状态转移方程即可 : 从子序列 i j 中取最大 = i + 从子序列i+1,j中取最大 或 j + 从子序列i,j-1中取最大
#include <algorithm>#include <cstring>#include <cstdio>using namespace std;const int maxn = 100+10;int S[maxn], A[maxn], d[maxn][maxn], vis[maxn][maxn], n;int dp(int i, int j){if (vis[i][j]) return d[i][j];vis[i][j] = 1;if (i == j) {d[i][j] = A[i];return d[i][j];}d[i][j] = max(A[i] + S[i+1,j] - dp(i + 1,j), A[j] + S[i,j - 1] - dp(i,j - 1));return d[i][j];}int main(){while (scanf("%d", &n) && n){S[0] = 0;for (int i = 1; i <= n;i++){scanf("%d", &A[i]);S[i] = S[i - 1] + A[i];}memset(vis, 0, sizeof(vis));printf("%d\n", 2*dp(1, n)-S[n]);}return 0;}
1 0
- [动态规划] Sum游戏 ( Game of Sum, Uva 10891 )
- UVA 10891 Game of Sum (动态规划)
- sum游戏 Game of sum uva 10891 动态规划 备忘录(记忆化搜索)
- uva 10891 - Game of Sum 动态规划 状态选取
- Game of Sum(动态规划)
- uva 10891 Game of Sum
- UVA 10891 Game of Sum
- UVa 10891 Game of Sum
- Uva-10891-Game of Sum
- Uva 10891 Game of Sum
- Uva - 10891 - Game of Sum
- uva 10891 - Game of Sum
- uva 10891 game of sum
- UVA 10891 Game of Sum
- UVa 10891 - Game of Sum
- UVA 10891 Game of Sum
- uva 10891 - Game of Sum
- UVA - 10891 Game of Sum
- arm-linux手工安装metasploit笔记
- 差分约束系统
- Linux内存管理(3) - slab分配器和kmalloc
- Android笔记——AutoCompleteTextView
- UVA 488 10038 10107 10370
- [动态规划] Sum游戏 ( Game of Sum, Uva 10891 )
- py 使用MyThread继承重写线程类实现多线程编程
- android中自定义dialog
- [LeetCode]131.Palindrome Partitioning
- static关键字
- 无线传感器网络
- Java内存溢出异常
- Python编程基础之三对象
- Ruby Digest(2)