usaco3.3.5 A Game
来源:互联网 发布:sql查询成绩相同语句 编辑:程序博客网 时间:2024/05/16 13:01
一 原题
IOI'96 - Day 1
Consider the following two-player game played with a sequence of N positive integers (2 <= N <= 100) laid onto a 1 x N game board. Player 1 starts the game. The players move alternately by selecting a number from either the left or the right end of the gameboar. That number is then deleted from the board, and its value is added to the score of the player who selected it. A player wins if his sum is greater than his opponents.
Write a program that implements the optimal strategy. The optimal strategy yields maximum points when playing against the "best possible" opponent. Your program must further implement an optimal strategy for player 2.
PROGRAM NAME: game1
INPUT FORMAT
Line 1:N, the size of the boardLine 2-etc:N integers in the range (1..200) that are the contents of the game board, from left to rightSAMPLE INPUT (file game1.in)
64 7 2 95 2
OUTPUT FORMAT
Two space-separated integers on a line: the score of Player 1 followed by the score of Player 2.SAMPLE OUTPUT (file game1.out)
18 11
二 分析
三 代码
USER: Qi Shen [maxkibb3]TASK: game1LANG: C++Compiling...Compile: OKExecuting... Test 1: TEST OK [0.000 secs, 4264 KB] Test 2: TEST OK [0.000 secs, 4264 KB] Test 3: TEST OK [0.000 secs, 4264 KB] Test 4: TEST OK [0.000 secs, 4264 KB] Test 5: TEST OK [0.000 secs, 4264 KB] Test 6: TEST OK [0.000 secs, 4264 KB] Test 7: TEST OK [0.000 secs, 4264 KB] Test 8: TEST OK [0.000 secs, 4264 KB] Test 9: TEST OK [0.000 secs, 4264 KB] Test 10: TEST OK [0.000 secs, 4264 KB] Test 11: TEST OK [0.000 secs, 4264 KB] Test 12: TEST OK [0.000 secs, 4264 KB] Test 13: TEST OK [0.000 secs, 4264 KB] Test 14: TEST OK [0.000 secs, 4264 KB] Test 15: TEST OK [0.000 secs, 4264 KB] Test 16: TEST OK [0.000 secs, 4264 KB]All tests OK.Your program ('game1') produced all correct answers! This is yoursubmission #2 for this problem. Congratulations!
/*ID:maxkibb3LANG:C++PROG:game1*/#include<cstdio>#include<algorithm>using namespace std;const int MAXN = 105;int n;int a[MAXN];int sum[MAXN][MAXN];int dp[MAXN][MAXN];int main() { freopen("game1.in", "r", stdin); freopen("game1.out", "w", stdout); scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &a[i]); sum[i][i] = a[i]; dp[i][i] = a[i]; } for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { sum[i][j] = sum[i][j - 1]; sum[i][j] += a[j]; } } for(int i = 1; i < n; i++) { for(int j = 0; j < n - i; j++) { dp[j][j + i] = max(a[j] + sum[j + 1][j + i] - dp[j + 1][j + i], a[j + i] + sum[j][j + i - 1] - dp[j][j + i - 1]); } } printf("%d %d\n", dp[0][n - 1], sum[0][n - 1] - dp[0][n - 1]); return 0;}
- usaco3.3.5 A Game
- [USACO3.3.5]A Game
- USACO3.3.5 A Game (game1)
- USACO3.3.5 A Game (game1)
- [USACO3.3]游戏 A Game
- Cpp环境【USACO3.3.5】【CQYZOS1256】A Game 游戏
- 动规——【USACO3.3.5】A Game游戏 IOI'96
- 【USACO3.3.5】一个游戏
- A Game
- A Game
- A. Game
- A. Game
- A Simple FPS Game
- UESTC1141 A Simple Game
- 1087. A Funny Game
- [院赛]A number game
- A Multiplication Game
- usaco A Game
- Theano 中文文档 0.9 - 7.2.6 Theano如何处理形状信息
- 【JavaEE】Java的13个规范
- 项目开发结构与工具
- 配置GLEW+GLFW并使用Xcode写OpenGL应用
- 【Android开发艺术探索读书笔记】第二章 Android中的多进程模式
- usaco3.3.5 A Game
- RabbitMQ--02--RabbitMQ传递对象
- ES6 Proxy/Reflect 浅析
- GitHub技巧
- Spring源码学习之spring设计理念和整体架构
- A == B?
- 基于python的互联网软件测试开发(自动化测试)-全集合
- jquery设置cookie自动登录
- 合纵连横