昨天比赛的时候这一题没看明白, No one gets credits in a tied game. 始终看不懂这句话什么意思,很悲催 后来才知道是平局的意思英语不行吖~
题意:
Alex, the team leader, has the privilege to arrange the game order. He wants to maximum his credit. Alex是队长,可以任意安排比赛顺序,求他(第一位选手)最后的最大得分~
ps:平局不得分,不管赢、输、平局经验都会增加
分析:
显然他要和其它n-1个人打一遍,接下来就是怎么安排打的顺序了,枚举显然不行,最大是13!会超时~
这里可以用到状态压缩,DP[i]表示比赛过的人状态为i,获得的最大分,因为N不是很大求经验是可以直接求,也可以事先打表
//AC CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bitset>
using namespace std;
#define Max(a,b) a>b?a:b
int dp[(1<<12)+2];//DP[i]比赛过的人状态为i,获得的最大分
int n;
struct node
{
int w;
int e;
int s;
}arr[20];
void in()
{
int tmp,i;
scanf("%d",&n);
for(i=0; i<n; i++)
scanf("%d",&(arr[i].e));
for(i=n; i<n*n; i++)//无用数据
scanf("%d",&tmp);
for(i=0; i<n; i++)
scanf("%d",&(arr[i].w));
for(i=n; i<n*n; i++)//无用数据
scanf("%d",&tmp);
for(i=0; i<n; i++)
scanf("%d",&(arr[i].s));
}
int get_bit(int num, int index)//取num中的index位
{
return (num>>(index))&1;
}
int getE(int k)
{
int sumE=0;
for(int i=0;i<n;i++)
{
if(get_bit(k,i))
sumE+=arr[i+1].e;
}
return sumE+arr[0].s;
}
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
in();
//DP 忽略srr[i]下标为0的
memset(dp,0,sizeof(dp));
dp[0]=0;
//
for(int i=0;i<(1<<(n-1));i++)
{
for(int j=0;j<n-1;j++)
{
if( !(i&(1<<j)) )//根据i得到他所获得的经验,此处可以打表
{
if( getE(i)>arr[j+1].s)
dp[i|(1<<j)]=Max(dp[i|(1<<j)],dp[i]+arr[j+1].w);
}
}
}
printf("%d\n",dp[(1<<(n-1))-1]);
}
return 0;
}