poj 2626 三维dp 0 1 bag

Chess
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2529 Accepted: 1159

Description

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.

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,以dp[i][j][k]表示从前i个人中选j个下黑子k个下白子的最大能力值,以 a[ i ][ 0 ]和 a[ i ][ 1 ]表示第i名选手下黑白子的能力,那么轻易得出递推方程 

dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k]+a[ i ][ 0 ],dp[i-1][j][k-1]+a[ i ][ 1 ]


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int a[1010][3];
int dp[1010][20][20];

int main()
{
    int pos=0;
    while(~scanf("%d%d",&a[pos][0],&a[pos][1]))
        pos++;

    dp[0][1][0]=a[0][0];
    dp[0][0][1]=a[0][1];
    for(int i=1;i<pos;i++)
        for(int j=0;j<16;j++)
            for(int k=0;k<16;k++){
                if(j)
                    dp[i][j][k]=max(dp[i][j][k],max(dp[i-1][j][k],dp[i-1][j-1][k]+a[i][0]));
                if(k)
                    dp[i][j][k]=max(dp[i][j][k],max(dp[i-1][j][k],dp[i-1][j][k-1]+a[i][1]));
            }

    printf("%d\n",dp[pos-1][15][15]);

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值