好苦逼,为啥数组开小了,不会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-]);
}
}

hdu 4620 搜索的更多相关文章

  1. hdu 5887 搜索+剪枝

    Herbs Gathering Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  3. Square HDU 1518 搜索

    Square HDU 1518 搜索 题意 原题链接 给你一定若干个木棒,让你使用它们组成一个四边形,要求这些木棒必须全部使用. 解题思路 木棒有多种组合方式,使用搜索来进行寻找,这里需要进行优化,不 ...

  4. HDU 4620 Fruit Ninja Extreme 搜索

    搜索+最优性剪枝. DFS的下一层起点应为当前选择的 i 的下一个,即DFS(i + 1)而不是DFS( cur + 1 ),cur+1代表当前起点的下一个.没想清楚,TLE到死…… #include ...

  5. HDU 4620 Fruit Ninja Extreme(2013多校第二场 剪枝搜索)

    这题官方结题报告一直在强调不难,只要注意剪枝就行. 这题剪枝就是生命....没有最优化剪枝就跪了:如果当前连续切割数加上剩余的所有切割数没有现存的最优解多的话,不需要继续搜索了 #include &l ...

  6. hdu 4848 搜索+剪枝 2014西安邀请赛

    http://acm.hdu.edu.cn/showproblem.php?pid=4848 比赛的时候我甚至没看这道题,事实上不难.... 可是说实话,如今对题意还是理解不太好...... 犯的错误 ...

  7. hdu 4620 Fruit Ninja Extreme

    Fruit Ninja Extreme Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. poj 1198 hdu 1401 搜索+剪枝 Solitaire

    写到一半才发现能够用双向搜索4层来写,但已经不愿意改了,干脆暴搜+剪枝水过去算了. 想到一个非常水的剪枝,h函数为  当前点到终点4个点的最短距离加起来除以2.由于最多一步走2格,然后在HDU上T了, ...

  9. hdu 1495 (搜索) 非常可乐

    http://acm.hdu.edu.cn/showproblem.php?pid=1495 搜索模拟出每此倒得情况就好,详情见代码\ (好困啊!!!!1) #include<cstdio> ...

随机推荐

  1. Oracle 11g 虚拟列 Virtual Column介绍

    Oracle 11G 虚拟列 Virtual Column Oracle 11G 在表中引入了虚拟列,虚拟列是一个表达式,在运行时计算,不存储在数据库中,不能更新虚拟列的值. 定义一个虚拟列的语法: ...

  2. C#一些小技巧(二)

    教你们怎么改配色方案,因为本人智障了很久,每次想改颜色的时候都会看到一大圈的选项,难以琢磨,但是智障了那么久终于被我找到了所有的关联. 首先,要告诉你们的是,其实C#里面要改的东西只有那么几个,但是注 ...

  3. 反射(学习整理)----Class类和加载器ClassLoader类的整理

    1.学习反射的时整理的笔记!Class类和ClassLoader类的简单介绍 反射机制中的Class Class内部到底有什么呢?看下图! 代码: Class cls=Person.class; .C ...

  4. 解决打不开jar包

    Java应用程序jar文件可以由 JVM(Java虚拟机)直接执行,只要操作系统安装了JVM便可以运行作为Java应用程序的jar文件,其跨平台特性使得很多工具软件都用jar方式来部署分发,比如用于H ...

  5. Java面向对象程序设计--接口和内部类

    1.接口的定义: In the Java programming language, an interface is not a class but          staff[0] =       ...

  6. 目前最流行的网页自动运行EXE文件

    大家对木马都不陌生了,它可能要算是计算机病毒史上最厉害的了,相信会使木马的人千千万万,但是有很多人苦于怎么把木马发给对方,现在随着计算机的普及,在网络上我相信很少有人会再轻易的接收对方的文件了,所以网 ...

  7. scala 安装

    http://www.scala-lang.org/download/install.html http://zh.scala-tour.com/#/hello-wolrd scala指南 To ru ...

  8. poj 2778 DNA Sequence AC自动机DP 矩阵优化

    DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11860   Accepted: 4527 Des ...

  9. bzoj 1059: [ZJOI2007]矩阵游戏 二分图匹配

    1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1891  Solved: 919[Submit][Statu ...

  10. Cow Marathon

    poj1985:http://poj.org/problem?id=1985 题意:就是树的直径. 题解:直接DFS即可. #include<iostream> #include<c ...