【BZOJ】2102: [Usaco2010 Dec]The Trough Game(暴力)
http://www.lydsy.com/JudgeOnline/problem.php?id=2102
直接枚举所有情况。。。。。。然后判断是否可行。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
#define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=105;
int n, m, cnt, ans, a[N][N], b[N]; bool check(int t) {
for1(i, 1, m) {
int tot=0;
rep(j, n) if(a[i][j] && (t&(1<<j))) ++tot;
if(tot!=b[i]) return 0;
}
return 1;
} int main() {
read(n); read(m);
for1(i, 1, m) {
rep(j, n) {
char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
a[i][j]=ch-'0';
}
b[i]=getint();
}
int mx=(1<<n)-1, flag=0;
for1(x, 0, mx) {
if(check(x)) {
if(cnt) { puts("NOT UNIQUE"); return 0; }
flag=1;
ans=x;
++cnt;
}
}
if(!flag) puts("IMPOSSIBLE");
else rep(i, n) printf("%d", (bool)(ans&(1<<i)));
return 0;
}
Description
Input
Output
Sample Input
1000 1
0110 1
1001 1
0011 1
Sample Output
HINT
Source
【BZOJ】2102: [Usaco2010 Dec]The Trough Game(暴力)的更多相关文章
- 2102: [Usaco2010 Dec]The Trough Game
2102: [Usaco2010 Dec]The Trough Game Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 117 Solved: 84[ ...
- BZOJ 2100: [Usaco2010 Dec]Apple Delivery( 最短路 )
跑两遍最短路就好了.. 话说这翻译2333 ---------------------------------------------------------------------- #includ ...
- BZOJ 2101: [Usaco2010 Dec]Treasure Chest 藏宝箱( dp )
dp( l , r ) = sum( l , r ) - min( dp( l + 1 , r ) , dp( l , r - 1 ) ) 被卡空间....我们可以发现 l > r 是无意义的 ...
- BZOJ2102 : [Usaco2010 Dec]The Trough Game
暴力枚举答案然后检验. #include<cstdio> int n,m,i,j,k,a[100],b[100],cnt,ans;char s[20]; int main(){ for(s ...
- BZOJ 2101 [Usaco2010 Dec]Treasure Chest 藏宝箱:区间dp 博弈【两种表示方法】【压维】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2101 题意: 共有n枚金币,第i枚金币的价值是w[i]. 把金币排成一条直线,Bessie ...
- BZOJ——2101: [Usaco2010 Dec]Treasure Chest 藏宝箱
http://www.lydsy.com/JudgeOnline/problem.php?id=2101 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: ...
- bzoj 2097: [Usaco2010 Dec]Exercise 奶牛健美操【二分+树形dp】
二分答案,然后dp判断是否合法 具体方法是设f[u]为u点到其子树中的最长链,每次把所有儿子的f值取出来排序,如果某两条能组合出大于mid的链就断掉f较大的一条 a是全局数组!!所以要先dfs完子树才 ...
- bzoj 2101: [Usaco2010 Dec]Treasure Chest 藏宝箱【区间dp】
就是区间dp啦f[i][j]表示以i开头的长为j+1的一段的答案,转移是f[i][j]=s[i+l]-s[i-1]+min(f[i][j-1],f[i+1][j-1]),初始是f[i][1]=a[i] ...
- bzoj 2100: [Usaco2010 Dec]Apple Delivery【spfa】
洛谷数据好强啊,普通spfa开o2都过不了,要加双端队列优化 因为是双向边,所以dis(u,v)=dis(v,u),所以分别以pa1和pa2为起点spfa一遍,表示pb-->pa1-->p ...
随机推荐
- struts2结合poi-3.7实现数据导出为excel
我们在处理数据的时候,有可能要将数据导出到excel文件中,那么java中是怎么实现的呢?apache开发的poi就可以帮我们实现啦,它也是开源的代码,导入相应的jar包,就可以轻松实现,下面让我们来 ...
- 让Vs2013 完美支持EF6.1 Code First with Oracle 2015年12月24日更新
本文是对下文的补充,切勿以为我是全盘复制哦 连接: http://www.cnblogs.com/wlflovenet/p/4187455.html Normal 0 7.8 磅 0 2 false ...
- 【java】对数据库操作的那些事(包含数据库中的预处理)
一.连接问题 前面刚介绍了怎么连接数据库,也写了对应的模板.可是它的可维护性很差.那么怎么解决问题呢? 首先写一个配置文件jdbc.properties <span style="fo ...
- JavaScript | 对象详解
————————————————————————————————————————————————————————— 对象有哪些(导图) 内建对象 数据封装对象 Object对象 Object.prot ...
- smartcar 系列机器人学习笔记1
总体框架: 1,感知一个相机,一个雷达,一个odom(非必须:一个imu)功能:车道线检测,红绿灯检测,障碍物检测 2,决策规划 功能:一次规划,(避障即:二次规划) 3,控制执行 功能:速度控制,角 ...
- 如何从官网下载Spring
1.Spring下载地址http://repo.spring.io/release/org/springframework/spring/ 里面有各自版本下载: 方法二: 1.在百度中输入Spring ...
- 使用Guava报错NoSuchMethodError的解决方法
在使用Guava缓存的时候.系统报错: java.lang.NoSuchMethodError: com.google.common.base.Objects.firstNonNull 错误原因就是找 ...
- C语言-常用函数处理
1.使用fgets #define SLEN 50 char str[SLEN]; fgets(str, SLEN, stdin); i = ; while (str[i] != '\n' & ...
- monogdb windows环境下 安装及使用简单示例
1,下载地址:http://www.mongodb.org/downloads,选择windows平台,当前最新的版本是:2.6.4,本机是64位win7系统,我选择的是windows 64位msi, ...
- [Android进阶]Binder学习(初始篇)
Android中Binder学习(初始篇) 本篇博客学习自侯亮的博客.地址为: 红茶一杯话Binder 1 什么是Binder? 简单地说.Binder是Android平台上的一种跨进程交互技术. 该 ...