Fruit Ninja Extreme

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 880    Accepted Submission(s): 231
Special Judge
Problem Description
Cut or not to cut, it is a question.

In Fruit Ninja, comprising three or more fruit in one cut gains extra bonuses. This kind of cuts are called bonus cuts.

Also, performing the bonus cuts in a short time are considered continual, iff. when all the bonus cuts are sorted, the time difference between every adjacent cuts is no more than a given period length of W.

As a fruit master, you have predicted the times of potential bonus cuts though the whole game. Now, your task is to determine how to cut the fruits in order to gain the most bonuses, namely, the largest number of continual bonus cuts.

Obviously, each fruit is allowed to cut at most once. i.e. After previous cut, a fruit will be regarded as invisible and won't be cut any more.

In addition, you must cut all the fruit altogether in one potential cut. i.e. If your potential cut contains 6 fruits, 2 of which have been cut previously, the 4 left fruits have to be cut altogether.
 
Input
There are multiple test cases.

The first line contains an integer, the number of test cases.

In each test case, there are three integer in the first line: N(N<=30), the number of predicted cuts, M(M<=200), the number of fruits, W(W<=100), the time window.

N lines follows.

In each line, the first integer Ci(Ci<=10) indicates the number of fruits in the i-th cuts.

The second integer Ti(Ti<=2000) indicate the time of this cut. It is guaranteed that every time is unique among all the cuts.

Then follow Ci numbers, ranging from 0 to M-1, representing the identifier of each fruit. If two identifiers in different cuts are the same, it means they represent the same fruit.

 
Output
For each test case, the first line contains one integer A, the largest number of continual bonus cuts.

In the second line, there are A integers, K1, K2, ..., K_A, ranging from 1 to N, indicating the (Ki)-th cuts are included in the answer. The integers are in ascending order and each separated by one space.  If there are multiple best solutions, any one is accepted.
 
Sample Input
1
4 10 4
3 1 1 2 3
4 3 3 4 6 5
3 7 7 8 9
3 5 9 5 4
 
Sample Output
3
1 2 3
 
Source
 
题意:
水果忍者模型。
N表示以下共有 N种切水果的方式。
M表示有M个水果需要你切。
W表示两次连续连击之间最大的间隔时间。
然后下N行描述的是 N种切法
第一个数字C表示这种切法可以切多少个水果。
第二个数字表示这种切法所处在的时间。
后C个数字表示此时这种切法所切掉的水果编号。
注意:同时切3个以上才表示连击,一个水果最多只能切一次。

思路:
按时间从小到大排序后,从前往后搜,不用回溯。

剪枝:
当前连击数+剩下能够切的次数<=ans时就不用搜了。

感想:
哎,没玩过水果忍者,比赛时把题意读错了。衰~   题意读懂后就是一般的搜索题了,其实不想写博客的,hdu上首次排名第一,纪念一下吧。

代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 31
using namespace std; int n,m,w,ans,num;
int a[maxn],ansa[maxn];
bool app[201];
struct Node
{
int id,cnt,time;
int v[11];
} pp[maxn]; bool cmp(const Node&xx,const Node&yy)
{
return xx.time<yy.time;
}
void dfs(int pos,int cxx,int pretime)
{
int i,j,t,tmp[11];
if(ans<cxx-1)
{
ans=cxx-1;
for(i=1; i<=ans; i++)
{
ansa[i]=pp[a[i]].id;
}
}
if(cxx+n-pos<=ans||ans==n||pos>n) return ;
if(pp[pos].time-pretime<=w)
{
t=0;
for(i=1; i<=pp[pos].cnt; i++)
{
if(app[pp[pos].v[i]]) t++;
}
if(t>=3)
{
for(i=1; i<=pp[pos].cnt; i++)
{
tmp[i]=app[pp[pos].v[i]];
app[pp[pos].v[i]]=0;
}
a[cxx]=pos;
dfs(pos+1,cxx+1,pp[pos].time);
for(i=1; i<=pp[pos].cnt; i++)
{
app[pp[pos].v[i]]=tmp[i];
}
}
dfs(pos+1,cxx,pretime);
}
else return ;
}
int main()
{
int i,j,t,u,sz;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&w);
for(i=1; i<=n; i++)
{
pp[i].id=i;
scanf("%d%d",&pp[i].cnt,&pp[i].time);
for(j=1; j<=pp[i].cnt; j++)
{
scanf("%d",&pp[i].v[j]);
}
}
sort(pp+1,pp+n+1,cmp);
ans=0;
memset(app,1,sizeof(app));
for(i=1; i<=n; i++)
{
a[1]=i;
for(j=1; j<=pp[i].cnt; j++)
{
app[pp[i].v[j]]=0;
}
dfs(i+1,2,pp[i].time);
for(j=1; j<=pp[i].cnt; j++)
{
app[pp[i].v[j]]=1;
}
}
sort(ansa+1,ansa+ans+1);
printf("%d\n",ans);
for(i=1; i<ans; i++)
{
printf("%d ",ansa[i]);
}
printf("%d\n",ansa[i]);
}
return 0;
}


hdu 4620 Fruit Ninja Extreme的更多相关文章

  1. HDU 4620 Fruit Ninja Extreme 搜索

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

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

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

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

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

  4. HDU 4620 Fruit Ninja Extreme 暴搜

    题目大意:题目就是描述的水果忍者. N表示以下共有 N种切水果的方式. M表示有M个水果需要你切. W表示两次连续连击之间最大的间隔时间. 然后下N行描述的是 N种切发 第一个数字C表示这种切法可以切 ...

  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 4116 Fruit Ninja

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

  8. hdu - 3952 Fruit Ninja(简单几何)

    思路来自于:http://www.cnblogs.com/wuyiqi/archive/2011/11/06/2238530.html 枚举两个多边形的两个点组成的直线,判断能与几个多边形相交 因为最 ...

  9. HDU 4000 Fruit Ninja 树状数组 + 计数

    给你N的一个排列,求满足:a[i] < a[k] < a[j] 并且i < j < k的三元组有多少个. 一步转化: 求出所有满足 a[i] < a[k] < a[ ...

随机推荐

  1. JSP页面中文参数传递get和post方法分析

    原文 http://developer.51cto.com/art/200907/133499.htm 在项目中,我们经常遇到需要在JSP页面切换中传递中文字符.这主要有两种方式. ◆URL方式 例如 ...

  2. 【转】Android(4.2) Sensors 学习——G-sensor,Gyroscope驱动移植

    原文网址:http://blog.csdn.net/nxh_love/article/details/11804841 本人对驱动可谓是一点不懂,鉴于公司目前高驱动的人手不够,所以我也只能两眼一抹黑硬 ...

  3. 移植strace调试工具到arm平台

    strace工具是一个非常强大的工具,是调试程序的好工具.要移植到arm平台,就需要使用交叉编译工具编译生成静态链接的可执行文件.具体步骤如下:1.下载 strace-4.5.16     移植str ...

  4. Eclipse代码提示功能设置(Java & Eclipse+CDT C/C++)

    http://developer.51cto.com/art/200907/136242.htm http://blog.chinaunix.net/u/21684/showart_462486.ht ...

  5. SQL Server (MSSQLSERVER) 服务因 找不到指定的模块。 服务特定错误而停止。

    新装了sql server 2008,发现sqlserver 服务没法起来.查看系统日志是7024如下: 事件类型: 错误 事件来源: Service Control Manager 事件种类: 无 ...

  6. bzoj2243-染色(动态树lct)

    解析:增加三个变量lc(最左边的颜色),rc(最右边的颜色),sum(连续相同颜色区间段数).然后就是区间合并的搞法.我就不详细解释了,估计你已经想到 如何做了. 代码 #include<cst ...

  7. 《Java程序员面试笔试宝典》之为什么需要public static void main(String[] args)这个方法

    public staticvoid main(String[] args)为Java程序的入口方法,JVM在运行程序的时候,会首先查找main方法.其中,public是权限修饰符,表明任何类或对象都可 ...

  8. hdu 5033 Building (单调栈 或 暴力枚举 )

    Description Once upon a time Matt went to a small town. The town was so small and narrow that he can ...

  9. pyqt 同时勾选多个items(网友提供学习)

    框选多个item之后,用空格键可以勾选/去选多个item,效果如下图所示: http://oglop.gitbooks.io/pyqt-pyside-cookbook/list/img/checkbo ...

  10. pyQt事件处理

    Qt事件处理01 Qt处理事件的第二种方式:"重新实现QObject::event()函数",通过重新实现event()函数,可以在事件到达特定的事件处理器之前截获并处理他们.这种 ...