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-]);
}
}
hdu 4620 搜索的更多相关文章
- hdu 5887 搜索+剪枝
Herbs Gathering Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- Square HDU 1518 搜索
Square HDU 1518 搜索 题意 原题链接 给你一定若干个木棒,让你使用它们组成一个四边形,要求这些木棒必须全部使用. 解题思路 木棒有多种组合方式,使用搜索来进行寻找,这里需要进行优化,不 ...
- HDU 4620 Fruit Ninja Extreme 搜索
搜索+最优性剪枝. DFS的下一层起点应为当前选择的 i 的下一个,即DFS(i + 1)而不是DFS( cur + 1 ),cur+1代表当前起点的下一个.没想清楚,TLE到死…… #include ...
- HDU 4620 Fruit Ninja Extreme(2013多校第二场 剪枝搜索)
这题官方结题报告一直在强调不难,只要注意剪枝就行. 这题剪枝就是生命....没有最优化剪枝就跪了:如果当前连续切割数加上剩余的所有切割数没有现存的最优解多的话,不需要继续搜索了 #include &l ...
- hdu 4848 搜索+剪枝 2014西安邀请赛
http://acm.hdu.edu.cn/showproblem.php?pid=4848 比赛的时候我甚至没看这道题,事实上不难.... 可是说实话,如今对题意还是理解不太好...... 犯的错误 ...
- hdu 4620 Fruit Ninja Extreme
Fruit Ninja Extreme Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- poj 1198 hdu 1401 搜索+剪枝 Solitaire
写到一半才发现能够用双向搜索4层来写,但已经不愿意改了,干脆暴搜+剪枝水过去算了. 想到一个非常水的剪枝,h函数为 当前点到终点4个点的最短距离加起来除以2.由于最多一步走2格,然后在HDU上T了, ...
- hdu 1495 (搜索) 非常可乐
http://acm.hdu.edu.cn/showproblem.php?pid=1495 搜索模拟出每此倒得情况就好,详情见代码\ (好困啊!!!!1) #include<cstdio> ...
随机推荐
- 使用oracle的SQL Developer创建用户的方法
这里针对的是Oracle11g,其它版本的没测试过不知道. 首先,使用system建立连接,密码是你安装时指定的那个密码,然后在最下面的“其它用户”中创建一个新用户. 注意1:创建完毕后一定要注意要在 ...
- gulp之css,js压缩合并加密替换
为了防止客户端的静态资源缓存,我们需要每次更新css或js的时候,通过md5或时间戳等方式重新命名静态资源.让客户端可以重新请求资源,而不是从缓存里取.然后html模板里的src也要做相应的修改.当然 ...
- WampServer修改MySQL密码
WampServer安装后密码是空的,需要设置一下 一般有两种方式: 一是通过phpMyAdmin直接修改: 二是使用WAMP的MySql控制台修改. 第一种: ①在phpMyAdmin界面中点击[用 ...
- Fast Report Data Filter
使用Data Filter两种方式:一种是 直接在Filter 属性里写表达式 ,另外一种就是在beforePrint 事件里写方法. 今天开发时遇到了一个Filter的问题,不知道是不是fast r ...
- UVA10142/PC110108Australian Voting
UVA10142/PC110108Australian Voting 10142 Australian Voting Accepted C++11 0.769 2014-02-11 05:01:20 ...
- PHP设计模式之:策略模式
<?phpabstract class Strategy{ public abstract function AlgorithmInterface();} class ConcreteSt ...
- destoon代码从头到尾捋一遍
destoon® B2B网站管理系统(以下简称destoon)由西安嘉客信息科技有限责任公司独立研发并推出,对其拥有完全知识产权,中国国家版权局计算机软件著作权登记号:2009SR037570. 系统 ...
- CANoe 入门 Step by step系列(二)CAPL编程【转】
CAPL就是Communication Application Programming Laguage的缩写,CAPL类似于C语言的语法,因此所有的语法请参考C语言教程,这里不在这里进行详述,关于C语 ...
- iOS: 学习笔记, 添加一个带界面约束的控制器
1. 创建一个空iOS应用程序(Empty Application). 2. 添加加控制器类. 修改控制器类的viewDidLoad - (void)viewDidLoad { [super view ...
- 简单学C——第三天
控制结构(二) 前面我们已经了解到了,控制结构中的判断结构,当然switch语句也是判断语句.不过如果if...else...语句你会了,我相信switch语句你也一定会的,它们的功能都是差不 ...