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. [原]C# 常用函数统计

    1.获取MD5 string MD5Compute(string strPwd) { MD5CryptoServiceProvider m5 = new MD5CryptoServiceProvide ...

  2. 禁用ViewPager左右两侧拉到边界的渐变颜色

    Android ViewPager在拖拽到左边和右边的时候,禁止显示黄色或者蓝色的渐变图片的解决方法 先说明哦,想看看院里的,从头开始看,否则,就拉到最下面啦.解决方案就在最下面. 修改前: 修改后: ...

  3. 创建Maven创建src/main/java提示反复

    建立好一个Maven项目后.假设Java Resources资源文件下没有src/main/java目录,而且在手动创建这个文件时提示"已存在文件". 这说明,在这个项目配置中已经 ...

  4. IIS------如何占用80端口

    如何占用80端口 请看我的一篇随笔: https://www.cnblogs.com/tianhengblogs/p/9292347.html

  5. SpringMVC由浅入深day01_7入门程序小结

    7 入门程序小结 通过入门程序理解springmvc前端控制器.处理器映射器.处理器适配器.视图解析器用法. 前端控制器配置: 处理器映射器: 非注解处理器映射器(了解) 注解的处理器映射器(掌握) ...

  6. Mybatis整合通用Dao,Mybatis整合通用Mapper,MyBatis3.x整合通用 Mapper3.5.x

    Mybatis整合通用Dao,Mybatis整合通用Mapper,MyBatis3.x整合通用 Mapper3.5.x ============================== 蕃薯耀 2018年 ...

  7. php前端传过来的json数据丢失 (max_input_vars)

    开发向我反馈,前端业务页面提交数据用js将要传输的数据用json dump后,发给服务器,服务器在loads后发现数据是不全的. 这个问题困扰开发人员和运维人员.首先调整php.ini文件的上传文件数 ...

  8. PDF XSS

    漏洞测试: 下面,我们介绍如何把 JavaScript 嵌入到 PDF 文档之中.我使用的是迅捷 PDF 编辑器未注册版本 1.启动迅捷 PDF 编辑器打开一个 PDF 文件,或者使用“创建 PDF ...

  9. zabbix创建触发器

    1. 增加触发器 配置-->主机-->选择主机-->创建触发器 2. 配置触发器 3.查看触发器的状态 如果有问题会显示红色的问题

  10. popupWindow 在指定位置上的显示

    先看效果图,免得浪费大家时间,看是不是想要的效果 . 直接上代码 ,核心方法. private void showPopupWindow(View parent) { if (popupWindow  ...