- Time: 2016-03-28-18:46:36
- Title Number: [2016-03-28][hdu][1074][doing homework]
- The main topic: given n the time period of the operation of the Department and the completion of times, each subject each more than one day to deduct a copy, the minimum deduction points
- Analysis: N only 15, binary enumeration, state compression, enumerate the status of each account completion, update the next state, find the minimum value
#include <cstring>
#include <cstdio>
using namespace std;
const int maxstu = 1 << 16;
struct Cource{
char name[20];
int d,c;
}a[16];
struct mstatus{
int pre,cost,reduced,id;
Mstatus(inta= 0,intb= 0,intC= 0,intD= 0): Cost(a),reduced(b),Pre(C),ID(D){};
}dp[maxstu];
int vis[maxstu];
void print(int cur){
if(dp[cur].pre == 0){
printf("%s\n",a[ dp[cur].id ].name);
return ;
}
print(dp[cur].pre);
printf("%s\n",a[ dp[cur].id ].name);
}
int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i = 0;i < n;++i){
scanf("%s%d%d",a[i].name,&a[i].d,&a[i].c);
}
memset(vis,0,sizeof(vis));
dp[0] = mstatus(0,0,0,0);
for ( int i = 0 ; i < ( 1 << n ) - 1 ;++ i
for(int j = 0;j < n;++j){
int cur = 1 << j;
if((cur & i) == 0){
int curcost = dp[i].cost + a[j].c;
int curreduced = DP [ i . reduced + ( curcost <= a [ j . d 0 : curcost - a [ j . d
int nxtstatus = cur | i;
if(vis[nxtstatus]){
if(curreduced < dp[nxtstatus].reduced){
dp[nxtstatus] = mstatus(curcost,curreduced,i,j);
}
}else {
vis[nxtstatus] = 1;
dp[nxtstatus] = mstatus(curcost,curreduced,i,j);
}
}
}
}
int ans = dp[(1 << n) - 1].reduced;
printf("%d\n",ans);
print((1 << n) - 1);
}
return 0;
}
From for notes (Wiz)
[2016-03-28] [HDU] [1074] [Doing Homework]