(简单) dp HOJ 2091 Chess
来源:互联网 发布:碧柔防晒知乎 编辑:程序博客网 时间:2024/06/05 20:46
Chess
Source : Univ. of Alberta Local Contest 1999.10.16Time limit : 1 secMemory limit : 32 M
Submitted : 237, Accepted : 94
The Association of Chess Monsters (ACM) is planning their annual team match up against the rest of the world. The match will be on 30 boards, with 15 players playing white and 15 players playing black. ACM has many players to choose from, and they try to pick the best team they can. The ability of each player for playing white is measured on a scale from 1 to 100 and the same for playing black. During the match a player can play white or black but not both. The value of a team is the total of players' abilities to play white for players designated to play white and players' abilities to play black for players designated to play black. ACM wants to pick up a team with the highest total value.Input
Input consists of a sequence of lines giving players' abilities. Each line gives the abilities of a single player by two integer numbers separated by a single space. The first number is the player's ability to play white and the second is the player's ability to play black. There will be no less than 30 and no more than 1000 lines on input.
There are multiple test cases. Each case will be followed by a single line containing a "*".
Output
Output a single line containing an integer number giving the value of the best chess team that ACM can assemble.
Sample Input87 8466 7886 9493 8772 10078 6360 9177 6477 9187 7369 6280 6881 8374 6386 6853 8059 7368 7057 9493 6274 8070 7288 8575 9971 6677 6481 9274 5771 6382 9776 56*Sample Output
2506
题意:给出很多选手,他们能去黑组和白组中的其中一个,我们要凑成一个15人黑组,15人白组,而且要分数最高。
思路:很明显的一个动态规划吧 , 我们用dp[i][j][k] 表示前i个人,凑成黑组j个人,白组k个人的最高得分,那么状态转移方程为dp[i][j][k] = max(dp[i-1][j-1][k]+black[i],dp[i-1][j][k-1]+white[i]); 然后这里方程只跟i-1有关,所以dp可以减少一维,变成dp[j][k] = max(dp[j-1][k]+black[i],dp[j][k-1]+white[i],dp[j][k]); 然后j和k要倒着退,这个思想在背包里面有用到过。然后答案就是dp[15][15];
代码:
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<map>
#include<cstdio>
#include<string.h>
using namespace std;
const int inf = 0xfffffff;
int dp[20][20];
int white[1010];
int black[1010];
int n;
void solve()
{
for (int i = 0 ; i <= 15 ; ++i)
for (int j = 0 ; j <= 15 ; ++j)
dp[i][j] = -inf;
dp[0][0] = 0;
for (int i = 1 ; i <= n ; ++i)
{
for (int j = 15 ; j >= 0 ; --j)
{
for (int k = 15 ; k >= 0 ; --k)
{
if (k>=1 && dp[j][k-1]!=-inf)
dp[j][k] = max(dp[j][k],dp[j][k-1]+black[i]);
if (j>=1 && dp[j-1][k]!=-inf)
dp[j][k] = max(dp[j][k],dp[j-1][k]+white[i]);
}
}
}
printf("%d\n",dp[15][15]);
}
int main()
{
char buffer[110];
n = 0;
while (gets(buffer))
{
if (buffer[0]=='*')
{
solve();
n = 0;
continue;
}
++n;
sscanf(buffer,"%d%d",white+n,black+n);
}
}
0 0
- (简单) dp HOJ 2091 Chess
- HOJ 2091 Chess(三维简单DP)
- Hdu 4405 Aeroplane chess - 简单DP
- (简单) 状态压缩dp HOJ 2188 WordStack
- (简单)树形dp HOJ 2514 Perfect Service
- HOJ 10086方砖问题(简单DP)
- Chess(DP)
- HOJ 2322 Incomplete chess boards
- 简单概率dp(期望)-hdu-4405-Aeroplane chess
- 百度之星初赛(B)--Chess---简单dp
- Buy Tickets hoj 单调队列优化DP的简单应用
- (简单) 状态压缩dp HOJ 2665 Factory of XiaoE
- (简单) 状态压缩dp HOJ 2421 Hie with the Pie
- (简单) 树形dp HOJ 2500 Party at Hali-Bula
- H - Tickets——HOJ 简单一维DP
- POJ2626 chess 三维DP
- hdu4405Aeroplane chess【概率DP】
- hdu 4832 chess dp
- (简单) 状态压缩dp HOJ 2665 Factory of XiaoE
- (经典例题) POJ 1185 炮兵阵地
- (简单) 状态压缩dp HOJ 2421 Hie with the Pie
- OpenSessionInView词条
- (中等) 状态压缩dp HOJ 1894 Islands and Bridges
- (简单) dp HOJ 2091 Chess
- (简单) 博弈 HOJ 2128 S-Nim
- (中等) 最短路 HOJ 2132 Easter holidays
- Android之菜单一——选项菜单
- (中等) 动态规划 HOJ 2177 ICPC Strikes Again
- (中等) 树形dp HOJ 2178 Optical Fiber
- (简单) 不需要算法 HOJ 1019 Grandpa\'s Other Estate
- *数论 HOJ 3110 Remoteland
- 博弈论 HOJ 1122 Number Game
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
满庭芳二手房
满庭芳怎么样
满庭芳 苏轼
满庭芳格律
观山满庭芳
秦观 满庭芳
一曲满庭芳
满庭芳 秦观
满庭芳 新中式
满庭芳新中式
满庭芳装饰公司
满庭芳树雨中深
秦观满庭芳
满庭芳网站
满庭芳婚庆
满庭芳老菜馆
满庭芳 婚纱
转调满庭芳
满庭芳-新中式
淘宝 满庭芳
桃花满庭芳
满庭芳元
满庭芳是什么意思
满庭芳院
满庭芳菜馆
满庭芳园出租
满庭芳火锅
满庭芳19楼
满庭芳文化
满庭芳花园公寓
满庭芳 渔夫词
满庭芳好看吗
满庭芳园房屋出租
满庭芳词
满庭芳租房
满庭芳 碧水惊秋
燕郊满庭芳
周邦彦 满庭芳
满庭芳周邦彦
太太满庭芳团购
苏轼 满庭芳
程序博客网,程序员的互联网技术博客家园。csdn论坛精品 msdn技术资料都在这里