思路:

题目链接http://poj.openjudge.cn/practice/C17K/

状压dp。dp[i][j]表示第i - k人到第i人的状态为j的情况下前i人中最多有多少好人。

实现:

 #include <bits/stdc++.h>
using namespace std;
int dp[][];
struct node
{
int type, id1, id2;
bool f1, f2;
};
node a[];
bool same(bool a, bool b)
{
return (a && b) || (!a && !b);
}
int main()
{
int t, n, k;
cin >> t;
while (t--)
{
memset(dp, , sizeof dp);
cin >> n >> k;
string s;
getchar();
for (int i = ; i < n; i++)
{
getline(cin, s);
string tmp;
stringstream ss(s);
vector<string> v;
while (ss >> tmp) v.push_back(tmp);
if (v[][] == 'I')
{
a[i].type = ;
a[i].id1 = atoi(v[].c_str());
a[i].id2 = atoi(v[].c_str());
a[i].f1 = v[] == "good" ? true : false;
a[i].f2 = v[] == "good" ? true : false;
}
else
{
a[i].type = ;
a[i].id1 = atoi(v[].c_str());
a[i].f1 = v[] == "good" ? true : false;
}
} int msk = ( << k + ) - ;
dp[][] = ;
for (int i = ; i < n; i++)
{
memset(dp[i & ], , sizeof dp[i & ]);
for (int j = ; j < << k + ; j++)
{
if (i < k + && j >= << i) continue;
int tmp = j << & msk;
dp[i & ][tmp] = max(dp[i & ][tmp], dp[i - & ][j]);
if (a[i].type == )
{
int p1 = i - a[i].id1;
if (same(a[i].f1, j >> p1 & ))
{
dp[i & ][tmp | ] = max(dp[i & ][tmp | ], dp[i - & ][j] + );
}
}
else
{
int p1 = i - a[i].id1, p2 = i - a[i].id2;
bool g1 = j >> p1 & , g2 = j >> p2 & ;
if (!(same(a[i].f1, g1) && !same(a[i].f2, g2)))
dp[i & ][tmp | ] = max(dp[i & ][tmp | ], dp[i - & ][j] + );
}
}
}
int ans = ;
for (int i = ; i < << k + ; i++)
ans = max(ans, dp[n - & ][i]);
cout << ans << endl;
}
return ;
}

PKU_campus_2017_K Lying Island的更多相关文章

  1. openJudge C17K:Lying Island

    地址:http://poj.openjudge.cn/practice/C17K/ 题目: C17K:Lying Island 查看 提交 统计 提问 总时间限制:  2000ms 内存限制:  26 ...

  2. C17K:Lying Island

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

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

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

  4. uva 592 Island of Logic (收索)

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

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

  6. [LeetCode] Island Perimeter 岛屿周长

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

  7. 463. Island Perimeter

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

  8. Leetcode-463 Island Perimeter

    #463. Island Perimeter You are given a map in form of a two-dimensional integer grid where 1 represe ...

  9. LeetCode Island Perimeter

    原题链接在这里:https://leetcode.com/problems/island-perimeter/ 题目: You are given a map in form of a two-dim ...

随机推荐

  1. spring-jar包详解整理(大合集)

    转:https://blog.csdn.net/weisong530624687/article/details/50888094 spring.jar 是包含有完整发布模块的单个jar 包.但是不包 ...

  2. poj 1724 ROADS 解题报告

    题目链接:http://poj.org/problem?id=1724 题目意思:给出一个含有N个点(编号从1~N).R条边的有向图.Bob 有 K 那么多的金钱,需要找一条从顶点1到顶点N的路径(每 ...

  3. html5--6-67 阶段练习8-弹性三列布局

    html5--6-67 阶段练习8-弹性三列布局 学习要点 运用弹性盒子模型完成一个三列布局,加深对学过知识点的综合应用能力. 了解用百分比设置元素高度的方法. @charset="UTF- ...

  4. NOSQL安全攻击

    摘自:http://www.infoq.com/cn/articles/nosql-injections-analysis JSON查询以及数据格式 PHP编码数组为原生JSON.嗯,数组示例如下: ...

  5. 【转载】U3D 游戏引擎之游戏架构脚本该如何来写

    原文:http://tech.ddvip.com/2013-02/1359996528190113.html Unity3D 游戏引擎之游戏架构脚本该如何来写   2013-02-05 00:48:4 ...

  6. codeforces 667B B. Coat of Anticubism(水题)

    题目链接: B. Coat of Anticubism time limit per test 1 second memory limit per test 256 megabytes input s ...

  7. 嵌入式Linux学习方法——给那些彷徨者(上)

    要想学好嵌入式Linux,首先要解决两个重要问题: 1. 学什么? 2. 怎么学? 首先解决第一个问题. 嵌入式Linux的系统架构包括软件和硬件两个部分,如下图: 再来看看一个成熟的嵌入式产品的开发 ...

  8. 数据类型总结 (C++)

    数据类型总结 (C++) 作用 C++ 大小 取值范围 后缀 字符 char 1 -128~127   字符(无符号) unsigned char 1 0~255   宽字符 wchar_t 2   ...

  9. ndoejs后台查询数据库返回的值-进行解析

    JSON.parse(jsonstr); //可以将json字符串转换成json对象 JSON.stringify(jsonobj); //可以将json对象转换成json对符串

  10. FZU2277 Change(dfs序+树状数组)

    传送门 题意 q次操作,操作有两种: 1 v x k:a[v]+=x,a[v']+=x-k(v'是v的子节点)... 2 v:查询\(a[v]mod(10^9+7)\) 分析 子节点增加的值为\(x+ ...