https://vjudge.net/contest/372814#problem/E
标签:get 状压dp temp using mic pre else put bsp
https://vjudge.net/contest/372814#problem/E
n=15考虑状压dp
#include #define inf 2333333333333333
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(long long i=a;iusing namespace std;
long long T,n,tot,temp,ki,pre_pt,cur_pt;
long long f[116],t[116],pre[116];
struct node{
string name;
long long ddl;
long long t;
}a[100];
stackst;
void in(long long &x){
long long y=1;char c=getchar();x=0;
while(c‘0‘||c>‘9‘){if(c==‘-‘)y=-1;c=getchar();}
while(c‘9‘&&c>=‘0‘){ x=(x1)+(x3)+c-‘0‘;c=getchar();}
x*=y;
}
void o(long long x){
if(x0){p(‘-‘);x=-x;}
if(x>9)o(x/10);
p(x%10+‘0‘);
}
void init(){
memset(pre,0,sizeof(pre));
memset(f,0,sizeof(f));
memset(t,0,sizeof(t));
}
signed main(){
in(T);
while(T--){
init();
in(n);
For(i,1,n){
cin>>a[i].name;
in(a[i].ddl);
in(a[i].t);
}
tot=(11;
For(i,0,tot) f[i]=inf;
f[0]=0;
For(S,1,tot){
for(long long i=n-1;i>=0;i--){
if(S&(1i)){
temp=S^(1i);
ki=max((long long)0,t[temp]+a[i+1].t-a[i+1].ddl);
if(f[temp]+kif[S]){
f[S]=f[temp]+ki;
pre[S]=temp;
t[S]=t[temp]+a[i+1].t;
}
}
}
}
For(i,1,n+1){
if(i==1){
pre_pt=tot;
}
else{
cur_pt=pre[pre_pt];
temp=cur_pt^pre_pt;
For(j,0,n-1){
if((1temp)
st.push(a[j+1]);
}
pre_pt=cur_pt;
}
}
o(f[tot]);p(‘\n‘);
while(!st.empty()){
coutendl;
st.pop();
}
}
return 0;
}
https://vjudge.net/contest/372814#problem/E
标签:get 状压dp temp using mic pre else put bsp
原文地址:https://www.cnblogs.com/war1111/p/12878056.html
评论