hdu4620Fruit Ninja Extreme

Fruit Ninja Extreme

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1177    Accepted Submission(s): 321

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

2013 Multi-University Training Contest 2

Recommend

zhuyuanchen520

如果当前已经选择的方法数加上尚未判断的方法数依旧无法超越当前的最大值就返回

状压记录下路径

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
using namespace std;
vector<int>edge[40],cut[40];
int ans,vis[210],n,path,note[40];
struct Box
{
	int c,t,id;
	bool operator < (Box x)const
	{
		return t<x.t;
	}
}box[40];
void dfs(int from,int step)
{
	if(step+n-from<=ans)
		return;
	path|=1<<box[from].id-1;
	note[step]=path;
	ans=max(step,ans);
	for(int i=0;i<edge[from].size();i++)
	{
		int to=edge[from][i];
		int sum=0;
		for(int j=0;j<cut[box[to].id].size();j++)
		{
			int fruit=cut[box[to].id][j];
			if(vis[fruit]++==0)
				sum++;
		}
		if(sum>=3)
			dfs(to,step+1);
		for(int j=0;j<cut[box[to].id].size();j++)
		{
			int fruit=cut[box[to].id][j];
			vis[fruit]--;
		}
	}
	path^=1<<box[from].id-1;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int m,w;
		scanf("%d%d%d",&n,&m,&w);
		for(int i=1;i<=n;i++)
		{
			box[i].id=i;
			scanf("%d%d",&box[i].c,&box[i].t);
			cut[i].clear();
			int t;
			for(int j=0;j<box[i].c;j++)
			{
				scanf("%d",&t);
				cut[i].push_back(t);
			}
		}
		sort(box+1,box+n+1);
		for(int i=1;i<=n;i++)
		{
			edge[i].clear();
			for(int j=i+1;j<=n;j++)
				if(box[j].t-box[i].t<=w)
					edge[i].push_back(j);
		}
		ans=0;
		for(int i=1;i<=n;i++)
			if(cut[box[i].id].size()>=3)
			{
				memset(vis,0,sizeof(vis));
				for(int j=0;j<cut[box[i].id].size();j++)
				{
					int fruit=cut[box[i].id][j];
					vis[fruit]=1;
				}
				dfs(i,1);
			}
		printf("%d\n",ans);
		bool flag=0;
		for(int i=1;i<=n;i++)
		{
			if(flag)
				printf(" ");
			if(note[ans]>>i-1&1)
			{
				flag=1;
				printf("%d",i);
			}
		}
		puts("");
	}
}
时间: 2024-10-09 20:28:42

hdu4620Fruit Ninja Extreme的相关文章

[2012山东省第三届ACM大学生程序设计竞赛]——Fruit Ninja II

Fruit Ninja II 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2416 Time Limit: 5000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Have you ever played a popular game named "Fruit Ninja"? Fruit Ninja (known as Fruit Ninja

uva 11595 - Crossing Streets EXTREME(切割多边形)

题目链接:uva 11595 - Crossing Streets EXTREME 对初始平面进行切割,得到所有平面,然后处理出所有边,有公共边的两个平面之间可以到达,对于城市的权值可以加到点上,进出各加一次即可. #include <cstdio> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <complex> #in

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

Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game named "Fruit Ninja"?Fruit Ninja (known as Fruit Ninja HD on the iPad and Fruit Ninja THD for Nvidia Tegra 2 based Android devices) is a video game de

hdu 4000 Fruit Ninja 树状数组

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4000 Recently, dobby is addicted in the Fruit Ninja. As you know, dobby is a free elf, so unlike other elves, he could do whatever he wants.But the hands of the elves are somehow strange, so when he cuts

Android7.0 Ninja编译原理

############################################# 本文为极度寒冰原创,转载请注明出处 ############################################# 引言 使在Android N的系统上,初次使用了Ninja的编译系统.对于Ninja,最初的印象是用在了Chromium open source code的编译中,在chromium的编译环境中,使用ninja -C out/Default chrome命令,就可以利用源码编译出

hdu 4000Fruit Ninja 树状数组

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2048    Accepted Submission(s): 805 Problem Description Recently, dobby is addicted in the Fruit Ninja. As you know, dobby is a free elf, so unlik

extreme (思路讯)交换机 配置vlan

今日某网友,协助配置美国 一个牌子的extreme (思路讯)交换机.接口加入VLAN,之前接触过,赶紧去找手册,后来找到了.....为方便大家,我小结一下: config vlan default del port all (删除所有端口属于default的vlan) create vlan v2001(vlan名字)              ####config vlan v2001 tag 2001                ###属于v2001的 tag标记,正如我们所说的 vla

怎样使用ninja编译系统编译我们的程序?

使用ninja 配置自己的环境来使用ninja 构建程序 Android使用ninja Windows使用 调试 不使用VS 技巧 问题 Ninja的原意是忍者,忍者神龟的忍者,这里被google拿来用在他们的编译系统上,目标是替代make之类的构建器,因为他们觉得其它的构建器太慢了,为此他们做过对比,对于chrome之类的拥有几万个文件的超大程序来说,用ninja的话,几乎立即开始编译,而make几乎要等上个10秒钟才开始编译. Ninja的另外一个特点,其实不是他娘的特点,就是独立于编译系统

如何使用ninja编译系统编译我们的程序?

使用ninja 配置自己的环境来使用ninja 构建程序 Android使用ninja Windows使用 调试 不使用VS 技巧 问题 Ninja的原意是忍者,忍者神龟的忍者.这里被google拿来用在他们的编译系统上.目标是替代make之类的构建器,由于他们认为其他的构建器太慢了,为此他们做过对照,对于chrome之类的拥有几万个文件的超大程序来说,用ninja的话,差点儿马上開始编译,而make差点儿要等上个10秒钟才開始编译. Ninja的另外一个特点,事实上不是他娘的特点,就是独立于编