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] ...
随机推荐
- hdu 4739(状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4739 思路:状态压缩. #include<iostream> #include<cs ...
- ArcGIS GP应用-GP模型服务发布
1.双击模型名称打开运行窗体 2.在图上交互和窗体中输入数据后,点击确定运行模型,查看运行结果 3.在当前模型“缓冲区分析”的目录树上,右击含有图形(点.线.面)的节点,点击添加至显示,显示图片 4. ...
- 利用脚手架vue cli搭建vue项目
vue.js https://vuejs.org/ 基础: http://cn.vuejs.org/v2/guide/installation.html 1.安装需要利用npm包管理器,所以首先安装n ...
- nexus配置第三方库文件
进入nexus管理界面 默认用户名密码:admin/admin123 在左侧Views/Repositories中选择Repositories,然后在右侧的面板中选择3rd party,在下方arti ...
- SharePoint Managed Metadata 使用总结
前言 本文完全原创,转载请说明出处,希望对大家有用. 在SharePoint开发中,通常我们会将数据存储在列表,文档库或者直接存到数据库.但涉及到数据的层级结构时,用列表等存储实现并不是一件简单的事情 ...
- 如何使用java指令执行含package的class文件
代码文件存放在E:/Temp/JAVA_TEMP/tmp文件夹,代码如下: package tmp; public class Temp { public static void main(Strin ...
- PMP私有广告交易市场
[资源]互联网广告新知:半小时读懂PMP私有广告交易市场是什么? https://socialbeta.com/t/resource-what-is-pmp.html SocialBeta | 201 ...
- 多线程入门-第六章-线程的调度与控制之join
/* 线程合并:将指定的线程加入到当前线程,可以将两个交替执行的线程合并为顺序执行的线程,即单线程. 如在B线程中调用了A的join方法,则线程A执行完后,才会执行线程B. */ public cla ...
- Android技巧小结之新旧版本Notification
最近开发用到了通知功能,但有几个地方老是提示deprecated,然后就找了篇文章学习了下新旧版本的不同. Notification即通知,用于在通知栏显示提示信息. 在较新的版本中(API leve ...
- 未安装git lfs导致git下载不完整,没有错误提示
git clone命令没有报错. --recursive选项也加上了. cmake命令没有报错 make命令出错. 最后发现是因为没有安装git lfs,导致大文件下载不完整.最坑的是下载的时候也没有 ...