hdu 4620 Fruit Ninja Extreme
Fruit Ninja Extreme
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.
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.
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.
4 10 4
3 1 1 2 3
4 3 3 4 6 5
3 7 7 8 9
3 5 9 5 4
1 2 3
M表示有M个水果需要你切。
W表示两次连续连击之间最大的间隔时间。
然后下N行描述的是 N种切法
第一个数字C表示这种切法可以切多少个水果。
第二个数字表示这种切法所处在的时间。
后C个数字表示此时这种切法所切掉的水果编号。
注意:同时切3个以上才表示连击,一个水果最多只能切一次。
#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的更多相关文章
- 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 4620 Fruit Ninja Extreme(状压+dfs剪枝)
对t进行从小到大排序(要记录ID),然后直接dfs. 剪枝的话,利用A*的思想,假设之后的全部连击也不能得到更优解. 因为要回溯,而且由于每次cut 的数目不会超过10,所以需要回溯的下标可以利用一个 ...
- HDU 4620 Fruit Ninja Extreme 暴搜
题目大意:题目就是描述的水果忍者. N表示以下共有 N种切水果的方式. M表示有M个水果需要你切. W表示两次连续连击之间最大的间隔时间. 然后下N行描述的是 N种切发 第一个数字C表示这种切法可以切 ...
- hdu4620 Fruit Ninja Extreme
Fruit Ninja Extreme Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4000 Fruit Ninja 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4000 Recently, dobby is addicted in the Fruit Ninja. ...
- HDU 4116 Fruit Ninja
http://acm.hdu.edu.cn/showproblem.php?pid=4116 题意:给N个圆,求一条直线最多能经过几个圆?(相切也算) 思路:枚举中心圆,将其他圆的切线按照极角排序,并 ...
- hdu - 3952 Fruit Ninja(简单几何)
思路来自于:http://www.cnblogs.com/wuyiqi/archive/2011/11/06/2238530.html 枚举两个多边形的两个点组成的直线,判断能与几个多边形相交 因为最 ...
- HDU 4000 Fruit Ninja 树状数组 + 计数
给你N的一个排列,求满足:a[i] < a[k] < a[j] 并且i < j < k的三元组有多少个. 一步转化: 求出所有满足 a[i] < a[k] < a[ ...
随机推荐
- 我的Android进阶之旅------>Android拍照小例子
今天简单的学习了一下android拍照的简单实现. 当然该程序是个小例子,非常简单,没有什么复杂的操作,但是可以学习到Android 拍照API流程. 1.在布局文件中添加一个 surfaceView ...
- python3-day1(文件操作)
index: str.fomat() open file str.replace 一.新款str.fomat() 1.>>> '12'.zfill(5) '00012' 2.> ...
- web前端之 CSS引入第三方插件
引入第三方图标插件 - fontawesome 官网地址:http://fontawesome.io/ 1.下载图标插件包 下载地址:https://codeload.github.com/FortA ...
- java 面向过程实现万年历
public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-gener ...
- [think in java]知识点学习
java中 全部数值都有正负号,不存在无符号整数. java中的基本类型存储在堆栈中. 其它对象存储在堆中. java确保数组会被初始化,并且不能在它的范围之外被訪问. 下面代码在c和c++中是合法的 ...
- Spring 3.x企业应用开发实战(11)----基于@AspectJ配置切面
1.@AspectJ的JDK必须是JDK 5.0+ 基于@AspectJ配置切面 @AspectJ采用注解描述切点.增强,两者只是表达式方式不同,效果相同. @AspectJ语法基础-----切点表达 ...
- Android——SQLite实现面向对象CRUD
android中SQLite的使用,事实上倒也不难.可是与JDBC操作数据库相比,这个还是有点不顺手,并且我好久没写底层的封装了,使用SSM框架这些都不须要考虑......好了,废话不多说.以下直接建 ...
- 关于VS2008中的targetver.h文件
targerver.h文件的作用: 定义程序运行的环境,如限制程序只能在XP下运行,限制程序在只能在Vin7下运行 或限制程序只能在XP以上系统运行,或限制程序只能在Server2003以上系统运行. ...
- Android PackageManager基础知识
一.PackageManagerService启动过程 SystemServer首先启动,创建一个ServerThread线程来启动所有Android核心服务,其中PackageManagerServ ...
- Oracle 回忆录
简述 工作时间说短也不算短了,掐指一算差不多三年了吧.以前都没有写过Blog,仅偶尔对所学和所用到的做些许整理,后面竟然没有把那留下来,悲催啊!留不下来的整理不是好东西(*^__^*) 嘻嘻……,现在 ...