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 ...
随机推荐
- Springboot @webfilter @order filter过滤器
我们使用@WebFilter注解的时候发现注解里面没有提供可以控制执行顺序的参数 @WebFilter 的属性 属性名 类型 描述 filterName String 指定过滤器的 name 属性,等 ...
- 使用srvany.exe将程序安装成windows服务的详细教程
srvany.exe介绍 srvany.exe是Microsoft Windows Resource Kits工具集的一个实用的小工具,用于将任何EXE程序作为Windows服务运行.也就是说srva ...
- JS有趣的单线程
一.JS的执行特点 源于单线程的特性, JS在一段时间内只能执行一部分代码, 那么, 当有多块代码需要执行时, 就需要排队等候了. 二.单线程与异步事件 (1) 什么是异步事件? 异 ...
- form提交表单没接收到$_POST
分享一个最近做项目遇到的奇葩经历: 很奇怪的,我在弄一个表单提交的时候,后台验证就报了非post提交错误 我就郁闷了,我form明明写的method为post,不可能是非post错误啊 经历反应测试, ...
- ASP代码审计学习笔记 -5.文件下载漏洞
文件下载漏洞 漏洞代码: <% function download(f,n) on error resume next Set S=CreateObject("Adodb.Stream ...
- js当中null和{}区别
{}是一个不完全空的对象,因为他的原型链上还有Object呢,而null就是完全空的对象,啥也没有,原型链也没有,所以null instanceof Object === false;[]就更不用说了 ...
- Cufon在渲染网页字体你不知道的事
清单 1. 无效的 font-family 字体指定 <style> .introduction { font-family:'Baroque Script';} </style&g ...
- java远程连接access数据库
本文转载自http://www.voidcn.com/article/p-tlrtkqlp-k.html 1 rmijdbc远程连接access数据库 正常情况下,常用的数据库sql server, ...
- linux系统环境搭建
一.安装jdk 参考帖子 用yum安装JDK(CentOS) 1.查看yum库中都有哪些jdk版本 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [r ...
- Puppet nginx+passenger模式配置
Puppet nginx+passenger模式配置 一.简述:Puppet 运行在单台服务器上默认启动的是一个puppetmaster进程,当遇到client高并发的请求时,基于ruby的WEBRi ...