2005-2006 ACM-ICPC East Central North America Regional Contest (ECNA 2005) H.Two Ends
2015-08-18 18:32
573 查看
http://codeforces.com/gym/100650
分析:
比较水的题目。
给你一个序列,有两个人分别拿,每次只能拿最左或最右,其中一个是只会贪心的拿,问贪心的人最多能输几分。
写个DP搞两边就行了,给的序列是偶数个的(题意),所以2个2个搞,只有四种情况。
分析:
比较水的题目。
给你一个序列,有两个人分别拿,每次只能拿最左或最右,其中一个是只会贪心的拿,问贪心的人最多能输几分。
写个DP搞两边就行了,给的序列是偶数个的(题意),所以2个2个搞,只有四种情况。
#include <iostream> #include <sstream> #include <iomanip> #include <vector> #include <deque> #include <list> #include <set> #include <map> #include <stack> #include <queue> #include <bitset> #include <string> #include <numeric> #include <algorithm> #include <functional> #include <iterator> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <cctype> #include <complex> #include <ctime> typedef long long LL; const double pi = acos(-1.0); const long long mod = 1e9 + 7; using namespace std; int a[1005]; int dp[1005][1005]; int ans(int A,int B) { if(dp[A][B] != 0) return dp[A][B]; if(B - A == 1) return dp[A][B] = abs(a[A] - a[B]); int MAX1,MAX2; if(a[A + 1] >= a[B]) MAX1 = ans(A + 2,B) + a[A] - a[A + 1]; else MAX1 = ans(A + 1,B - 1) + a[A] - a[B]; if(a[A] < a[B - 1]) MAX2 = ans(A,B - 2) + a[B] - a[B - 1]; else MAX2 = ans(A + 1,B - 1) + a[B] - a[A]; return dp[A][B] = max(MAX1,MAX2); } int main() { //freopen("int.txt","r",stdin); //freopen("out.txt","w",stdout); int N; int t = 0; while(scanf("%d",&N) && N) { for(int i = 1;i <= N;i++) scanf("%d",&a[i]); memset(dp,0,sizeof(dp)); printf("In game %d, the greedy strategy might lose by as many as %d points.\n",++t,ans(1,N)); } return 0; }
相关文章推荐
- 侧滑菜单 ——仿QQ实现动画效果
- 死锁实例
- Spring rmi
- Struts2 全局结果类型<global-results>
- jvm内存模型
- java 中break、continue、return之间的区别与联系
- 解决firefox经常出现Adobe Flash 插件已崩溃
- C++逐行读取文本文件的正确做法
- sysfs创建目录:
- TCP堵塞控制
- adb shell 控制启动Activity、Service等
- 单链表 之c代码
- C++逐行读取文本文件的正确做法
- PySpark关于HDFS文件(目录)输入、数据格式的探讨
- Python学习 windows下面安装Python和pip(一)
- 在输入的字符串中判断是否有a,多种方法(比较前两种不同的表示方法)
- android studio的使用
- cocos-2dx 渲染(2)
- nginx对ip的访问频率进行限制(limit_req)和对ip连接数(并发量)进行限制(limit_conn)
- 我的openwrt学习笔记(六):MTK的OpenWrt系统编译以及下载