好苦逼,为啥数组开小了,不会runtime error,还得我WA了几个小时,我泪流满面。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4620
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> using namespace std; const int maxn = 35; struct Cut{ int T; int icnt; int bef_id; int a[11]; bool operator < (const Cut& r) const{ return T < r.T; } }cut[maxn]; int N,M,W; bool vis[400]; int ans[maxn],temp[maxn]; int anspv; void dfs(int now,int fa_time,int deep){ // printf("now,fa_time,deep %d %d %d ",now,fa_time,deep); if(deep > anspv){ anspv = deep; copy(temp,temp+anspv,ans); //for(int i=0;i<anspv;i++) printf("%d ",ans[i]); printf(" "); } if(now >= N) return; if(deep + N-now <= anspv) return; for(int i=now;i<N;i++){ if(cut[i].T - fa_time > W && fa_time != -1) continue; int sta[11],cnt =0; for(int j=0;j<cut[i].icnt;j++){ if(!vis[cut[i].a[j]]) sta[cnt++] = cut[i].a[j]; } if(cnt < 3) continue; for(int j=0;j<cnt;j++) vis[sta[j]] = true; temp[deep] = cut[i].bef_id; dfs(i+1,cut[i].T,deep+1); for(int j=0;j<cnt;j++) vis[sta[j]] = false; } } int main() { //freopen("E:\acm\input.txt","r",stdin); int T; cin>>T; while(T--){ cin>>N>>M>>W; int pv = 0; for(int i=1;i<=N;i++){ int c,time; scanf("%d %d",&c,&time); if(c<3) continue; cut[pv].icnt = c; cut[pv].bef_id = i; cut[pv].T = time; for(int i=0;i<c;i++) scanf("%d",&cut[pv].a[i]); pv++; } N = pv; sort(cut,cut+N); anspv = 0; memset(vis,0,sizeof(vis)); dfs(0,-1,0); sort(ans,ans+anspv); printf("%d ",anspv); for(int i=0;i<anspv-1;i++){ printf("%d ",ans[i]); } printf("%d ",ans[anspv-1]); } }