Fruit Ninja Extreme

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 900 Accepted Submission(s): 238
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
 
Recommend
zhuyuanchen520
水题 ,暴搜,就可以了,一个小小的剪枝,如果,当前得到的分加上,后来一直连切都比得到的结果要小于等于,可以直接剪掉!注意最后,是要排了序再输出的,这一点,错了几次, 尽量不要用 stl因为,这题 时间,卡的紧!
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
struct node{
int id,a[15],t,n;
bool operator <(node b)const{return t<b.t;}
}p[35];
int re[35],tep[35],visit[250],n,w,ans;
bool cmp(node a,node b)
{
return a<b;
}
bool cmp1(int a,int b){return a<b;}
int dfs(int step,int last,int goal)
{
int i,sum,j;
if(goal+n-step<=ans)
return -1;
for(i=step+1;i<n;i++)
{
if(step!=-1)
{
if(p[i].t-p[last].t>w)
break;
}
int prime[20],num;
for(j=0,sum=0,num=0;j<p[i].n;j++)
{
if(!visit[p[i].a[j]])
visit[p[i].a[j]]=1,prime[num++]=p[i].a[j],sum++;
}
if(sum>=3)
{
tep[goal+1]=p[i].id;
dfs(i,i,goal+1);
}
else
{
if(goal>ans)
{
ans=goal;
for(j=1;j<=goal;j++)
re[j]=tep[j];
}
}
for(j=0;j<num;j++)
visit[prime[j]]=0;
}
if(goal>ans)
{
ans=goal;
for(j=1;j<=goal;j++)
re[j]=tep[j];
}
return -1;
}
int main()
{
int tcase,m,i,j;
scanf("%d",&tcase);
while(tcase--)
{
scanf("%d%d%d",&n,&m,&w);
memset(visit,0,sizeof(visit));
for(i=0;i<n;i++)
{
scanf("%d%d",&p[i].n,&p[i].t);
p[i].id=i+1;
for(j=0;j<p[i].n;j++)
{
scanf("%d",&p[i].a[j]);
}
}
sort(p,p+n,cmp);
ans=0;
memset(visit,0,sizeof(visit));
dfs(-1,0,0);
printf("%d\n",ans);
sort(re+1,re+ans+1,cmp1);
for(i=1;i<=ans;i++)
{
if(i==1)printf("%d",re[1]);
else printf(" %d",re[i]);
}
if(ans)
printf("\n");
}
return 0;
}

hdu4620 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. HDU 4620 Fruit Ninja Extreme 暴搜

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

  6. sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)

    Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...

  7. SDUT 2416:Fruit Ninja II

    Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...

  8. hdu 4000 Fruit Ninja 树状数组

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

  9. Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

    Time Limit: 5000MS Memory limit: 65536K 题目描述 Haveyou ever played a popular game named "Fruit Ni ...

随机推荐

  1. Usaco 2.3 Zero Sums(回溯DFS)--暴搜

    Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...

  2. YII2 实现登录时候修改最新登录时间

    YII2 实现登录时候修改最新登录时间 YII2保存最新登录时间主要技巧:为 EVENT_AFTER_LOGIN 事件绑定一个方法,在方法中保存最新时间 public function login() ...

  3. CentOS 6.5 PYPI本地源制作

    转载:blog.csdn.net/tantexian   一.安装pip2pi工具: pip install pip2pi 或 git clone https://github.com/wolever ...

  4. web测试 结果存储类型为“Database”,但尚未指定结果储存库连接字符串

    vs2010 Ultimate版带有web测试功能,可以对网站的性能以及负载进行测试. 在进行负载测试时提示“异常 LoadTestConnectStringMissingException 1 Lo ...

  5. Python网络编程——修改套接字发送和接收的缓冲区大小

    很多情况下,默认的套接字缓冲区大小可能不够用.此时,可以将默认的套接字缓冲区大小改成一个更合适的值. 1. 代码 # ! /usr/bin/env python # -*- coding: utf-8 ...

  6. asp.net 开发注意的几点

    WIN7中组件服务中的DCOM配置找不到Microsoft Excel应用程序的解决办法: 这主要是64位系统的问题,excel是32位的组件,所以在正常的系统组件服务里是看不到的 可以通过在运行里面 ...

  7. fedora21安装无线驱动

    来源:http://www.2cto.com/os/201202/120249.html 一.导入rpmfushion源,使用第三方yum 源: su -c 'yum localinstall --n ...

  8. 数据结构——二叉搜索树(Binary Search Tree)

    二叉树(Binary Tree)的基础下 每个父节点下 左节点小,右节点大. 节点的插入: 若root==NULL则root=newnode 否则不断与节点值比较,较小则向左比较,较大则向右比较. 完 ...

  9. 九、cocos2dx之Actions

    本文由qinning199原创,转载请注明:http://www.cocos2dx.net/?p=86 Action是CCNode对象的一种顺序.这些动作经常改变对象的一些属性,比如位置,旋转,缩放等 ...

  10. 如何使用W5300实现ADSL连接(一)

    在介绍W5300连接ADSL之前,先给大家简单介绍一下WIZnet W5300这款芯片. W5300是WIZnet公司的一款单芯片器件,采用0.18μmCMOS工艺,内部集成10/100M以太网控制器 ...