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. MongoDB使用经验总结

    摘要: 最近在开发项目使用了数据库MongoDB,我将它的使用方法整理下分享给大家.至于mongoDB有什么优点,大家可以到官网去看. 安装: 首先我们需要到官网下载适合自己系统的mongodb. w ...

  2. RF采用SSHLibary库执行sudo命令,提示sudo: sorry, you must have a tty to run sudo错误的解决办法

    经了解Execute Command and Start Command两个关键字执行linux命令会新增一个shell,并且可能改变环境配置,如果要确保环境不被改变,则需采用Write和Read方法 ...

  3. SaltStack 批量安装软件

    这里我们用 SaltStack 服务端对多台客户端远程批量安装 httpd,步骤如下: [root@localhost ~]$ vim /etc/salt/master # 编辑配置文件,打开base ...

  4. Linux init 命令

    init命令用于切换到指定的运行级别,用法如下: [root@localhost ~]# init //关机 [root@localhost ~]# init //切换到单用户模式/救援模式 [roo ...

  5. oracle非空不做更新

    update test set B=nvl(p1,B),C=nvl(p2,C),D=nvl(p3,D),E=nvl(p4,E) where A='good'

  6. CentoOS6.6安装netcat

    http://blog.csdn.net/u013673976/article/details/47084841 CentOS下安装netcat 使用zookeeper过程中,需要监控集群状态.在使用 ...

  7. Java中有几种线程池?

    缓存,修正,计划,单一 newCachedThreadPool newFixedThreadPool newScheduleThreadPool newSingleThreadExecutor

  8. WP8.1学习系列(第十九章)——事件和路由事件概述

    我们将介绍在使用 C#.Visual Basic 或 Visual C++ 组件扩展 (C++/CX) 作为编程语言并使用 XAML 进行 UI 定义时,针对 Windows 运行时应用的事件的编程概 ...

  9. 【大数据系列】Hive安装及web模式管理

    一.什么是Hive Hive是建立在Hadoop基础常的数据仓库基础架构,,它提供了一系列的工具,可以用了进行数据提取转化加载(ETL),这是一种可以存储.查询和分析存储在Hadoop中的按规模数据的 ...

  10. vuex - 辅助函数学习

    官网文档: https://vuex.vuejs.org/zh-cn/api.html  最底部 mapState 此函数返回一个对象,生成计算属性 - 当一个组件需要获取多个状态时候,将这些状态都声 ...