PKU_campus_2017_K Lying Island
思路:
题目链接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的更多相关文章
- openJudge C17K:Lying Island
地址:http://poj.openjudge.cn/practice/C17K/ 题目: C17K:Lying Island 查看 提交 统计 提问 总时间限制: 2000ms 内存限制: 26 ...
- C17K:Lying Island
链接 题意: 有n个人,每个人可能会说: 第x个人是好人/坏人 如果第x个人是好人/坏人,则第y个人是好人/坏人 思路: 状压dp,首先每个人所说的人只能是他前面10个人,所以对于第i个人记录下,他前 ...
- 【状压DP】OpenJ_POJ - C17K Lying Island
https://vjudge.net/contest/171652#problem/K [题意] 小岛上有n个人,有些是好人(一定是真话),有些是坏人(可能是真话也可能是假话),现在要判断最多有多少好 ...
- 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] ...
- Leetcode-463 Island Perimeter
#463. Island Perimeter You are given a map in form of a two-dimensional integer grid where 1 represe ...
- LeetCode Island Perimeter
原题链接在这里:https://leetcode.com/problems/island-perimeter/ 题目: You are given a map in form of a two-dim ...
随机推荐
- js 中整理(一)
一. 冒泡与冒泡阻止 var arr={5,0,-56,900,12,9000,-123}; var flag=false; //大的排序次数(arr.length-1) for(var i=0; ...
- bzoj4149: [AMPPZ2014]Global Warming
头都烂了怎么头疼啊 考虑先做出对于一个位置以它作为唯一最小值的最远区间,这个可以单调栈上二分搞出来 那么对于一个位置这个区间而言,一定是选择这个区间的最大数是作为最终的唯一最大数最优的 为什么呢?我们 ...
- YTU 2209: 建立链表(线性表)
2209: 建立链表(线性表) 时间限制: 1 Sec 内存限制: 128 MB 提交: 282 解决: 185 题目描述 (线性表)设键盘输入n个英语单词,输入格式为n, w1, w2, -,w ...
- poj 1325 Machine Schedule 解题报告
题目链接:http://poj.org/problem?id=1325 题目意思:有 k 个作业,机器A有 n 个模式:0 ~ n-1,机器B 有 m 个模式:0~ m-1.每一个作业能运行在 A 的 ...
- Android零碎知识点,之后会一直更新的哦!
view的getCompoundDrawables()方法,调用这个方法返回的是控件的左上右下四个位置的Drawable,并且返回的类型是数据 setBounds(x,y,width,height); ...
- android:oneshot
帧动画的自动执行:oneshot . 如果为true,表示动画只播放一次停止在最后一帧上,如果设置为false表示动画循环播放.
- putty与emacs
win环境下putty登录到linux并使用emacs时,需要折腾好配置才能正常工作.下面是折腾过程中碰到的问题与解决步骤: 1)要在putty控制台中启用鼠标,只需要在.emacs配置文件中启用xt ...
- jQuery中排除指定元素,同时选择剩下的所有元素
场景:某页面用了js延时加载技术处理所有图片,以改善用户体验,但是有几个图片不想延时加载,要求把它们单独挑出来. 研究了一下jQuery的API文档,搞掂了,jQuery真的很方便,贴在这里备份: 1 ...
- IT行业怎么了?程序员按时上下班也被开除
转自:https://blog.csdn.net/keymo_/article/details/7783389 近日看了一条新闻是京东员工按时上下班遭“被离职”.话说一员工入职一个多月以来,每天保质保 ...
- A. Mishka and Game
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...