HOJ 2091 Chess(三维简单DP)
Chess
My Tags (Edit)
Source : Univ. of Alberta Local Contest 1999.10.16
Time limit : 1 sec Memory limit : 32 M
Submitted : 244, Accepted : 100
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 Input
87 84
66 78
86 94
93 87
72 100
78 63
60 91
77 64
77 91
87 73
69 62
80 68
81 83
74 63
86 68
53 80
59 73
68 70
57 94
93 62
74 80
70 72
88 85
75 99
71 66
77 64
81 92
74 57
71 63
82 97
76 56
*
Sample Output
2506
如果能想到用三维表示状态,就很容易了
dp[i][j][k]表示到第i个人已经选了j个人去打白选了k个人去打黑
那么dp[i][j][k]只有三种情况,在第i个人要么不选他,要么选他打白,要么选他打黑
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
int dp[1005][20][20];
int a[1005];
int b[1005];
char c[1005];
char d[1005];
int fun(char *a)
{
int len=strlen(a);
int num=0;
for(int i=0;i<len;i++)
{
num+=(a[i]-'0')*(int)(pow(10,(len-i-1)));
}
return num;
}
int main()
{
while(scanf("%s",c)!=EOF)
{
scanf("%s",d);
int cnt=0;
while(true)
{
a[++cnt]=fun(c);
b[cnt]=fun(d);
scanf("%s",c);
if(c[0]=='*')
break;
else
scanf("%s",d);
}
memset(dp,0,sizeof(dp));
for(int i=1;i<=cnt;i++)
{
for(int j=0;j<=15;j++)
{
for(int k=0;k<=15;k++)
{
if(j+k>i)
continue;
if(!j&&k)
dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j][k-1]+b[i]);
else if(j&&!k)
dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-1][k]+a[i]);
else if(!j&&!k)
dp[i][j][k]=dp[i-1][j][k];
else
dp[i][j][k]=max(dp[i-1][j][k],max(dp[i-1][j-1][k]+a[i],dp[i-1][j][k-1]+b[i]));
}
}
}
printf("%d\n",dp[cnt][15][15]);
}
return 0;
}
HOJ 2091 Chess(三维简单DP)的更多相关文章
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu1087 简单DP
I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB ...
- 4.15 每周作业 —— 简单DP
免费馅饼 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- codeforces Gym 100500H A. Potion of Immortality 简单DP
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- 简单dp --- HDU1248寒冰王座
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- poj 1157 LITTLE SHOP_简单dp
题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...
- hdu 2471 简单DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=( dp[n-1][m],dp[n][m-1],d[i][k ...
随机推荐
- linux(redhat)环境下,如何解压rar文件?
需求描述: 今天一个同事发过来一个压缩文件,让传送到linux服务器上,传上去之后,发现是rar格式的 之前没有解压过,就找了一些解压方法,在此记录下. 操作过程: 1.下载rar在linux环境下的 ...
- js提取新浪邮箱的信用卡
js提取用户新浪邮箱中的信用卡信息,是js非nodejs. 对比py,之前就做不好,出现了复杂点选验证码.js的开发速度只需要py的三分之一,甚至十分之一. js在客户端执行,py在后端执行,py要实 ...
- Window系统、主函数和窗体函数这三者之间的关系
理解Window系统.主窗体.窗体函数这三者之间的关系,对于编写Windows程序十分重要. 主函数和窗体函数都是由Windows系统来调用的函数.仅仅只是主函数是程序启动之后.系统首先调用的函数: ...
- spring mvc处理方法返回方式
Model: package org.springframework.ui; import java.util.Collection; import java.util.Map; public int ...
- Yii 汉化翻译
一).首先创建一个zh_cn语言包.(参考网址:制作语言包) 1.复制framework\messages\config.php 文件到 protected\messages\下 2.更改config ...
- Mybatis整合通用Dao,Mybatis整合通用Mapper,MyBatis3.x整合通用 Mapper3.5.x
Mybatis整合通用Dao,Mybatis整合通用Mapper,MyBatis3.x整合通用 Mapper3.5.x ============================== 蕃薯耀 2018年 ...
- Redis 未授权访问漏洞(附Python脚本)
0x01 环境搭建 #下载并安装 cd /tmp wget http://download.redis.io/releases/redis-2.8.17.tar.gz tar xzf redis-.t ...
- STL——配接器(adapters)
一.配接器 <Design Patterns>一书提到23个最普及的设计模式,其中对adapter样式的定义如下:将一个class的接口转换为另一个class 的接口,使原本因接口不兼容而 ...
- Oracle和Mysql中mybatis模糊匹配查询区别
1.Oracle AND NAME LIKE '%'||#{name}||'%' 2.Mysql AND NAME LIKE "%"#{name}"%"
- Xshell 5 免费版本安装过程
发现本机的Xshell 5过期了用不了.在百度里搜索,下载安装后还是不可以使用.需要购买注册,后寻的一方法,分享给大家. 1.官网 进入官网,然后点击Download下方的Free License菜单 ...