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] ...
随机推荐
- 漫游kafka实战篇之搭建Kafka开发环境(3)
上篇文章中我们搭建了kafka的服务器,并可以使用Kafka的命令行工具创建topic,发送和接收消息.下面我们来搭建kafka的开发环境. 添加依赖 搭建开发环境需要引入kafka的jar包 ...
- python 发送email
pyton smtplib发送邮件 在邮件中设置并获取到 smtp域名 在脚本中执行命名,收件人可以是 多个,在列表中 import smtplib from email.mime.text impo ...
- web版pdf在线阅读器
近期论坛里有人提到了,在线pdf阅读器怎么做.我百度了一下,发现非常多人都非常懒.程序猿都非常懒吗? 答案是否定的. 为什么都不愿意去搜索一下呢.网上非常多答案的.我这里就列举一例.大家共勉. 看代码 ...
- .Net CCNet C#6.0 自动化编译问题解决
一.问题描述 由于C#6.0一些新的语法特性,导致先前部署的CCNet持续集成平台出现问题,无论是手动还是命令行均不能编译. 二.解决方案 1.下载BuildTools_Full.exe,地址:h ...
- Text Particle Systems
一.简介 在一些企业广告或者网站需要一些动态文字特效的时候,往往有下面这几种选择: 1.Flash制作的文字特效 2.制作一个动态的GIF 3.Javascript+dom+css 4.SVG 二.j ...
- Java Web项目BlogAutoGenerator编写日志1
使用的数据库是MySQL,所以首先要在MySQL中创建database和表.建立数据库article_db,建立表blog,如下: create database article_db DEFAULT ...
- Mybatis整理系列(01)————传入参数方式以及#{}与${}的区别
一.在MyBatis的select.insert.update.delete这些元素中都提到了parameterType这个属性.MyBatis现在可以使用的parameterType有基本数据类型和 ...
- MySQL- INSTR 函数的用法
测试数据库: MYSQL数据库 INSTR(STR,SUBSTR) 在一个字符串(STR)中搜索指定的字符(SUBSTR),返回发现指定的字符的位置(INDEX); STR 被搜索的字符串 SUBST ...
- linLINUX中常用操作命令
LINUX中常用操作命令 Linux简介及Ubuntu安装 常见指令 系统管理命令 打包压缩相关命令 关机/重启机器 Linux管道 Linux软件包管理 vim使用 用户及用户组管理 文件权限管理 ...
- linux下安装JDK,及配置环境变量
首先去官网https://www.oracle.com/technetwork/java/javase/downloads/index.html下载最新的JDK版本: 以下操作在root用户下操作 第 ...