题目大意:题目就是描述的水果忍者。

N表示以下共有 N种切水果的方式。

M表示有M个水果需要你切。

W表示两次连续连击之间最大的间隔时间。

然后下N行描述的是 N种切发

第一个数字C表示这种切法可以切多少个水果。

第二个数字表示这种切法所处在的时间。

后C个数字表示此时这种切法所切掉的水果编号。

注意:同时切3个以上才表示连击,一个水果最多只能切一次。

思路:直接暴搜,再去加剪枝。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std; int gap,n,m;
int vis[205]; int tans[35];//开手动栈,不然容易超时
int ans[35];
int tanstop;
int anstop; struct node
{
vector<int>num;
int cnt;
int time;
int id;
bool operator < (const node &cmp) const
{
return time<cmp.time;
}
}cut[35]; void dfs(int ttime,int pos)
{
if(m-pos+tanstop<=anstop) return;//如果之后的全部放上来还比当前ANS小,那就不用继续了 A*思想
for(int i=pos+1;i<=m;i++)
{
if(cut[i].time-ttime<=gap||!tanstop)//每一次都可以作为起点。所以加上!tanstop
{
int tot=0;
int SIZE=cut[i].num.size();
for(int j=0;j<SIZE;j++)
{
if(vis[cut[i].num[j]]==0)
{
tot++;
}
vis[cut[i].num[j]]++;
}
if(tot>=3)
{
tans[tanstop++]=cut[i].id;
dfs(cut[i].time,i);
tanstop--;
}
for(int j=0;j<SIZE;j++)
vis[cut[i].num[j]]--;
}
else break;//如果此时时间已无法连击 后面的也就不行了
}
if(tanstop>anstop)
{
anstop=0;
for(int i=0;i<tanstop;i++)
ans[anstop++]=tans[i];
} } int main()
{
int T;
scanf("%d",&T);
while(T--)
{
tanstop=anstop=0; memset(vis,0,sizeof(vis)); scanf("%d%d%d",&m,&n,&gap); for(int i=1;i<=m;i++)
{
cut[i].num.clear();
scanf("%d%d",&cut[i].cnt,&cut[i].time);
cut[i].id=i;
for(int j=0;j<cut[i].cnt;j++)
{
int tmp;
scanf("%d",&tmp);
cut[i].num.push_back(tmp);
}
if(cut[i].cnt<=2){i--;m--;}
} sort(cut+1,cut+m+1);//按时间把切水果的方式排序 方便DFS dfs(1,0); printf("%d\n",anstop); sort(ans,ans+anstop);//要求升序输出 for(int i=0;i<anstop-1;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[anstop-1]);
}
return 0;
}

HDU 4620 Fruit Ninja Extreme 暴搜的更多相关文章

  1. hdu 4620 Fruit Ninja Extreme

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

  2. HDU 4620 Fruit Ninja Extreme 搜索

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

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

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

  4. hdu 4620 Fruit Ninja Extreme(状压+dfs剪枝)

    对t进行从小到大排序(要记录ID),然后直接dfs. 剪枝的话,利用A*的思想,假设之后的全部连击也不能得到更优解. 因为要回溯,而且由于每次cut 的数目不会超过10,所以需要回溯的下标可以利用一个 ...

  5. hdu4620 Fruit Ninja Extreme

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

  6. hdu 4000 Fruit Ninja 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4000 Recently, dobby is addicted in the Fruit Ninja. ...

  7. hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)

    Mines Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  8. HDU 5961:传递(暴搜)

    http://acm.hdu.edu.cn/showproblem.php?pid=5961 题意:中文题意.给出两个图,判断这个两个图是否都是传递的.注意一下传递的定义要看清,一开始没看清连样例都看 ...

  9. HDU 4116 Fruit Ninja

    http://acm.hdu.edu.cn/showproblem.php?pid=4116 题意:给N个圆,求一条直线最多能经过几个圆?(相切也算) 思路:枚举中心圆,将其他圆的切线按照极角排序,并 ...

随机推荐

  1. hihocoder #1301 : 筑地市场 二分+数位dp

    #1301 : 筑地市场 题目连接: http://hihocoder.com/problemset/problem/1301 Description 筑地市场是位于日本东京都中央区筑地的公营批发市场 ...

  2. ZOJ 3626 Treasure Hunt I 树上DP

    E - Treasure Hunt I Time Limit:2000MS Memory Limit:65536KB Description Akiba is a dangerous country ...

  3. C#高级编程9 第11章 Linq

    Linq 1.Linq概述 列表和实体 准备数据: public class Championship { public int Year { get; set; } public string Fi ...

  4. Qt线程外使用Sleep

    一:方法1 QTime t; t.start(); while(t.elapsed()<1000){     QCoreApplication::processEvents();} 二:方法2 ...

  5. nginx新建nginx_fzjh.conf文件,不使用默认配置文件

    worker_processes 4; events{ worker_connections 1024; } http{ server { listen 80; server_name myserve ...

  6. Install WordPress Plugins without FTP Access

    WordPress will only prompt you for your FTP connection information while trying to install plugins o ...

  7. C/C++服务器开发的必备利器–libconfig

    http://www.leoox.com/?p=311 程序肯定需要一份配置文件,要不然,自己的程序不是“可配置”的,自己都不好意思往“高大上”靠拢.言归正传,以前自己写代码,配置文件的读写都是各式各 ...

  8. 安装wp8sdk 当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内。

    安装wp8sdk 当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内. [1404:0090][2015-06-12T08:00:53]: Error 0x800b0101: Failed ...

  9. nginx简单代理配置

    原文:https://my.oschina.net/wangnian/blog/791294 前言  Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器, ...

  10. xcode找不到真机设备 - 转

    先确认证书是否正确 再确认Bundle Indentifier 是否与证书匹配 再确认Deployment Target 为:sdk从6.0改为4.3 如果xcode还无法识别iphone, Xcod ...