hdu 4620 搜索

时间:2023-03-09 16:26:53
hdu 4620 搜索

好苦逼,为啥数组开小了,不会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 = ; struct Cut{
int T;
int icnt;
int bef_id;
int a[];
bool operator < (const Cut& r) const{
return T < r.T;
}
}cut[maxn];
int N,M,W;
bool vis[];
int ans[maxn],temp[maxn];
int anspv; void dfs(int now,int fa_time,int deep){ // printf("now,fa_time,deep %d %d %d\n",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("\n");
}
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 != -) continue;
int sta[],cnt =;
for(int j=;j<cut[i].icnt;j++){
if(!vis[cut[i].a[j]])
sta[cnt++] = cut[i].a[j];
}
if(cnt < ) continue;
for(int j=;j<cnt;j++)
vis[sta[j]] = true; temp[deep] = cut[i].bef_id;
dfs(i+,cut[i].T,deep+); for(int j=;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 = ;
for(int i=;i<=N;i++){
int c,time;
scanf("%d %d",&c,&time);
if(c<) continue;
cut[pv].icnt = c;
cut[pv].bef_id = i;
cut[pv].T = time;
for(int i=;i<c;i++)
scanf("%d",&cut[pv].a[i]);
pv++;
}
N = pv;
sort(cut,cut+N); anspv = ;
memset(vis,,sizeof(vis));
dfs(,-,);
sort(ans,ans+anspv);
printf("%d\n",anspv);
for(int i=;i<anspv-;i++){
printf("%d ",ans[i]);
}
printf("%d\n",ans[anspv-]);
}
}