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)的更多相关文章

  1. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. hdu1087 简单DP

    I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     ...

  3. 4.15 每周作业 —— 简单DP

    免费馅饼 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissi ...

  4. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  5. 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 ...

  6. 简单dp --- HDU1248寒冰王座

    题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...

  7. poj2385 简单DP

    J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit ...

  8. poj 1157 LITTLE SHOP_简单dp

    题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...

  9. 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 ...

随机推荐

  1. 2018-10-29 A股主要指数的市盈率(PE)估值高度

    全指材料(SH000987) - 2018-10-29日,当前值:11.9289,平均值:30.66,中位数:26.1407,当前 接近历史新低.全指材料(SH000987)的历史市盈率PE详情 全指 ...

  2. 【Postgres】PostgreSQL配置远程连接

    1.开启相应的防火墙端口,缺省是5432 2.访问权限配置,D:\Program Files (x86)\PostgreSQL\9.2\data/pg_hba.conf中加入如下配置,开启远程访问 3 ...

  3. 【代码审计】EasySNS_V1.6远程图片本地化导致Getshell

    0x00 环境准备 EasySNS官网:http://www.imzaker.com 网站源码版本:EasySNS极简社区V1.60 程序源码下载:http://es.imzaker.com/inde ...

  4. javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed

    1.使用HttpClient4.3 调用https出现如下错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.Validat ...

  5. jQuery ajax中serialize()方法增加其他参数

    表单提交 使用jQuery.ajax()进行表单提交时,需要传递参数,最直接的方法便是使用Form的serializa()将表单序列化,前提只是将Form表单中的name属性与数据库的字段名保持一致便 ...

  6. XPath的初步认识

    嘿嘿,最近开始上班,不是过于太忙,而是自己一直在学习一些项目中用到的而我暂时还没接触的知识,WCF,log4等,感觉还没有总结的需要吧,虽然都了解啦,但是暂时还是初步的学习,基础的暂时是知道啦,还没有 ...

  7. Android学习之BitMap用法实例

    下面简单说明了BitMap的用法: 从服务器下载一张图片,显示在ImageView控件上,并将该图片保存在移动设备的SD上. // 根据网络URL获取输入流 public InputStream ge ...

  8. 禁用Visual Studio 2013的Browser Link功能 -调试不断请求http://localhost:6154/c4ad1c693ebf428283832eaa827f9c6e/arterySignalR/poll?transport=longPolling...

    关于禁用查到的解决: 作者:donny945 https://my.oschina.net/ind/blog/359003 今天浏览器调试代码的时候,一直出现以下的请求,导致需要看的请求都被淹没了,之 ...

  9. 删除sql注入

    ), );--过滤字符串 字符串及之后的数据将被替换为空 set @FilterStr='</title><style>.alx2{'; set @curTable='user ...

  10. JSON类库 Flexjson学习

    官方地址(需FQ):http://flexjson.sourceforge.net/ Flexjson 是一个将 Java 对象转成 JSON 的 类库,是一个深度转换的过程. 下面是我写的一个例子: ...