地址: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的更多相关文章

  1. C17K:Lying Island

    链接 题意: 有n个人,每个人可能会说: 第x个人是好人/坏人 如果第x个人是好人/坏人,则第y个人是好人/坏人 思路: 状压dp,首先每个人所说的人只能是他前面10个人,所以对于第i个人记录下,他前 ...

  2. 【状压DP】OpenJ_POJ - C17K Lying Island

    https://vjudge.net/contest/171652#problem/K [题意] 小岛上有n个人,有些是好人(一定是真话),有些是坏人(可能是真话也可能是假话),现在要判断最多有多少好 ...

  3. PKU_campus_2017_K Lying Island

    思路: 题目链接http://poj.openjudge.cn/practice/C17K/ 状压dp.dp[i][j]表示第i - k人到第i人的状态为j的情况下前i人中最多有多少好人. 实现: # ...

  4. Poj 1328 / OpenJudge 1328 Radar Installation

    1.Link: http://poj.org/problem?id=1328 http://bailian.openjudge.cn/practice/1328/ 2.Content: Radar I ...

  5. OpenJudge/Poj 1753 Flip Game

    1.链接地址: http://bailian.openjudge.cn/practice/1753/ http://poj.org/problem?id=1753 2.题目: 总时间限制: 1000m ...

  6. uva 592 Island of Logic (收索)

      Island of Logic  The Island of Logic has three kinds of inhabitants: divine beings that always tel ...

  7. 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 ...

  8. [LeetCode] Island Perimeter 岛屿周长

    You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...

  9. 463. Island Perimeter

    https://leetcode.com/problems/island-perimeter/ 在一个N×N的矩阵中,N<100,1代表岛,0代表海,岛内没有海,求岛的周长 [[0,1,0,0] ...

随机推荐

  1. 终端利用ssh登录远程服务器

    第一步: 安装ssh:yum  install ssh 第二步: 启动ssh服务:service sshd start 第三步: 连接远程服务器: ssh -p 端口号 用户名@ip地址      然 ...

  2. Hadoop1.x目录结构及Eclipse导入Hadoop源码项目

    这是解压hadoop后,hadoop-1.2.1目录 各目录结构及说明: Eclipse导入Hadoop源码项目: 注意:如果没有ant的包可以去网上下,不是hadoop里面的. 然后如果通过以上还报 ...

  3. Qt slot中获取sender

    调用sender();函数 例如获取一个QRadioButton QRadioButton *rb = qobject_cast<QRadioButton *>(sender());

  4. angular的属性绑定

    1. 图片地址属性绑定 html文件 <img [src]="imgUrl"> ts文件 export class ProductComponent implement ...

  5. powerdesinger导出数据库说明文档

    设置表结构要展示的属性,以及各个属性的展示列宽 不显示标题 右键单击items,选择format,然后Available栏中选择ListText选项卡,设置表格边框 保存为模板,Report-> ...

  6. PHP array_merge() 函数

    <?php $a1=array("a"=>"red","b"=>"green"); $a2=array ...

  7. kubernetes基础知识:限制POD和容器运行的CPU、内存

    限制运行内存 https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/ 先看一个pod的yaml ...

  8. js对用户信息加密传输 java后端解密

    1.加密采用服务端随机生成加密因子放入session中,传入登录或注册界面(每次进入都刷新) 2.页面中引入jquery.aes.js(这个js从网上下的坑比较多,引入先后顺序不一致都会报错,所以最后 ...

  9. windows accounts

    Some built-in groups are used for management purposes. You control which > users belong to these ...

  10. 算法大神之路——排序

    从今天开始,给自己立下一个目标,每天晚上写一篇算法与数据结构的博客,用来给自己以后的算法工程师的目标铺路! 今天晚上就以算法里面的排序,作为自己的第一章节吧. 排序,就是讲一组数据,按照特定的规则去调 ...