openJudge C17K:Lying Island
地址:http://poj.openjudge.cn/practice/C17K/
题目:
C17K:Lying Island
- 总时间限制:
- 2000ms
- 内存限制:
- 262144kB
- 描述
-
There are N people living on Lying Island. Some of them are good guys, while others are bad.
It is known that good guys are always telling truths, while bad guys may be telling either truths or lies.
One day, an investigator came to Lying Island. He wondered how many good guys are there on the island. So he conducted an investigation.
People on the island are numbered from 1 to N. When the investigator was interviewing person i, he showed the islander the information about at most K people numbered from max{i-K,1} to (i-1).
Sometimes, the i-th islander would say, "Oh, person x is a good(bad) guy."
But sometimes, the i-th islander would mince his words, "Eh, if person x is a good(bad) guy, person y is a good(bad) guy."
Of course, x and y is less than i but no less than (i-K), because person i only saw the information of that at most K islanders.
The investigator does not think he can infer exactly how many good guys on the island from these words, but he feels that he can figure out how many good guys at most on the island. Can you help him?
- 输入
- The first line contains an integer T (1 <= T <= 50), indicating the number of test cases.
For each test case:
The first line contains two integers N and K (0 <= N <= 5000,1 <= K <= 10).
Then (N-1) lines follow, each line contains a string, indicating the sentences said by person 2 to person N. Each sentence is in one of the following formats:
1. Person i: Person x is a good guy.
2. Person i: Person x is a bad guy.
3. Person i: If person x is a good guy, person y is a good guy.
4. Person i: If person x is a bad guy, person y is a bad guy.
It is guaranteed that in each sentence, max{1,i-K} <= x,y < i and x ≠ y. - 输出
- For each test case, output one integer on a single line, indicating the number of good guys at most on the island.
- 样例输入
-
2
7 2
Person 2: Person 1 is a good guy.
Person 3: Person 2 is a bad guy.
Person 4: If person 3 is a good guy, person 2 is a good guy.
Person 5: If person 4 is a good guy, person 3 is a bad guy.
Person 6: If person 5 is a bad guy, person 4 is a good guy.
Person 7: If person 6 is a bad guy, person 5 is a bad guy.
7 4
Person 2: Person 1 is a bad guy.
Person 3: Person 2 is a bad guy.
Person 4: If person 3 is a good guy, person 1 is a bad guy.
Person 5: Person 2 is a bad guy.
Person 6: If person 4 is a good guy, person 2 is a bad guy.
Person 7: Person 6 is a bad guy. - 样例输出
-
6
4 - 提示
- For the first test case, person 3 is a bad guy, and others are good.
Person 1: Person 1 said nothing, he is a good guy.
Person 2: Person 1 is indeed a good guy, and person 2 is saying the truth.
Person 3: Person 2 is not a bad guy, and person 3 is lying.
Person 4: Person 3 is not a good guy, so the prerequisite does not met. Person 4 is saying the truth.
Person 5: Person 4 is indeed a good guy and person 3 is indeed a bad guy. Person 5 is saying the truth.
Person 6: Person 5 is a good guy. Person 6 is saying the truth.
Person 7: Person 6 is a good guy. Person 7 is saying the truth. - 思路:状压DP,把包括当前位的前十位状压进去就好了,然后转移。
-
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=5e3+;
const int mod=1e9+; int n,ans,k,dp[K][<<];
char sa[]; int main(void)
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
memset(dp,-,sizeof dp);
for(int i=,mx=(<<);i<mx;i++)
dp[][i]=;
for(int i=(<<),mx=(<<);i<mx;i++)
dp[][i]=;
for(int i=,x,y,dx,dy;i<=n;i++)
{
scanf("%s%d%s%s",sa,&x,sa,sa);
if(sa[]=='P')
{
scanf("%d%s%s%s",&x,sa,sa,sa);
if(sa[]=='b') dx=;
else dx=;
gets(sa);
for(int j=,mx=<<;j<mx;j++)
if(((j>>(x-i+))&)==dx&&~dp[i-][j])
dp[i][(j+mx)>>]=max(dp[i-][j]+,dp[i][(j+mx)>>]);
for(int j=,mx=(<<);j<mx;j++)
dp[i][j>>]=max(dp[i][j>>],dp[i-][j]);
}
else
{
scanf("%s%d%s%s%s",sa,&x,sa,sa,sa);
if(sa[]=='b') dx=;
else dx=;
scanf("%s%s%d%s%s%s",sa,sa,&y,sa,sa,sa);
if(sa[]=='b') dy=;
else dy=;
gets(sa);
for(int j=,mx=<<;j<mx;j++)
if(~dp[i-][j] && !(((j>>(x-i+))&)==dx&&((j>>(y-i+))&)!=dy))
dp[i][(j+mx)>>]=max(dp[i-][j]+,dp[i][(j+mx)>>]);
for(int j=,mx=(<<);j<mx;j++)
dp[i][j>>]=max(dp[i-][j],dp[i][j>>]);
}
}
ans=;
for(int i=,mx=(<<);i<mx;i++)
ans=max(ans,dp[n][i]);
printf("%d\n",ans);
}
return ;
} /*
Person 2: Person 1 is a bad guy.
Person 3: Person 2 is a bad guy.
Person 4: Person 3 is a bad guy.
Person 5: Person 4 is a bad guy. Person 2: Person 1 is a good guy.
Person 3: Person 2 is a good guy.
Person 4: Person 3 is a bad guy.
Person 5: Person 4 is a good guy.
*/
openJudge C17K:Lying Island的更多相关文章
- C17K:Lying Island
链接 题意: 有n个人,每个人可能会说: 第x个人是好人/坏人 如果第x个人是好人/坏人,则第y个人是好人/坏人 思路: 状压dp,首先每个人所说的人只能是他前面10个人,所以对于第i个人记录下,他前 ...
- 【状压DP】OpenJ_POJ - C17K Lying Island
https://vjudge.net/contest/171652#problem/K [题意] 小岛上有n个人,有些是好人(一定是真话),有些是坏人(可能是真话也可能是假话),现在要判断最多有多少好 ...
- PKU_campus_2017_K Lying Island
思路: 题目链接http://poj.openjudge.cn/practice/C17K/ 状压dp.dp[i][j]表示第i - k人到第i人的状态为j的情况下前i人中最多有多少好人. 实现: # ...
- Poj 1328 / OpenJudge 1328 Radar Installation
1.Link: http://poj.org/problem?id=1328 http://bailian.openjudge.cn/practice/1328/ 2.Content: Radar I ...
- OpenJudge/Poj 1753 Flip Game
1.链接地址: http://bailian.openjudge.cn/practice/1753/ http://poj.org/problem?id=1753 2.题目: 总时间限制: 1000m ...
- uva 592 Island of Logic (收索)
Island of Logic The Island of Logic has three kinds of inhabitants: divine beings that always tel ...
- LightOJ 1418 Trees on My Island (Pick定理)
题目链接:LightOJ 1418 Problem Description I have bought an island where I want to plant trees in rows an ...
- [LeetCode] Island Perimeter 岛屿周长
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...
- 463. Island Perimeter
https://leetcode.com/problems/island-perimeter/ 在一个N×N的矩阵中,N<100,1代表岛,0代表海,岛内没有海,求岛的周长 [[0,1,0,0] ...
随机推荐
- hrbustoj 1104:Leyni, LOLI and Line(解析几何,斜截式的应用)
Leyni, LOLI and Line Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 181(54 users) Tota ...
- Docker 使用及常用命令
https://yeasy.gitbooks.io/docker_practice/content/image/dockerfile/expose.html docker practice 资料 -- ...
- jQuery------$.each()遍历类方法
方法一:(推荐) //遍历city类<div name = 'city' class = 'city'></div> var ck = $(".city") ...
- .Net CCNet C#6.0 自动化编译问题解决
一.问题描述 由于C#6.0一些新的语法特性,导致先前部署的CCNet持续集成平台出现问题,无论是手动还是命令行均不能编译. 二.解决方案 1.下载BuildTools_Full.exe,地址:h ...
- 关于metaspolit中进行JAVA反序列化渗透RMI的原理分析
一.背景: 这里需要对java反序列化有点了解,在这里得推广下自己的博客嘛,虽然写的不好,广告还是要做的.原谅我: 1.java反序列化漏洞原理研习 2.java反序列化漏洞的检测 二.攻击手法简介 ...
- Microsoft License Keys – Volume
VLK Product Group Product KeyOffice XP Applications P3HBK-F86Y2-374PQ-KW92R-B36VTOffice 2003 Suites ...
- Android之內置、外置SDCard
From:http://blog.csdn.net/u011290399/article/details/10363881 在项目中,发现通过Android提供的API获取外置SDCard的操作一直不 ...
- How to Design a Good API and Why it Matters
前谷歌首席 Java 架构师谈如何设优秀的 API – 码农网 http://www.codeceo.com/article/google-java-good-api.html 2015-11-24 ...
- LMAX Disruptor 原理
http://mechanitis.blogspot.com/search/label/disruptor http://ifeve.com/disruptor/, 并发框架Disruptor译文 h ...
- virt-manager 操作 kvm虚拟机中鼠标不同步的问题
在/etc/libvirt/qemu下找到对应的xml配置文件 在<devices>标签下添加 <input type='tablet' bus='usb'/> 然后 vi ...