M - M

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

SAT was the first known NP-complete problem. The problem remains NP-complete even if all expressions are written in conjunctive normal form with 3 variables per clause (3-CNF), yielding the 3-SAT problem. A K-SATproblem can be described as follows:

There are n persons, and m objects. Each person makes K wishes, for each of these wishes either he wants to take an object or he wants to reject an object. You have to take a subset of the objects such that every person is happy. A person is happy if at least one of his K wishes is kept. For example, there are 3 persons, 4 objects, and K = 2, and

Person 1 says, "take object 1 or reject 2."

Person 2 says, "take object 3 or 4."

Person 3 says, "reject object 3 or 1."

So, if we take object 1 2 3, then it is not a valid solution, since person 3 becomes unhappy. But if we take 1 2 4 then everyone becomes happy. If we take only 4, it's also a valid solution. Now you are given the information about the persons' wishes and the solution we are currently thinking. You have to say whether the solution is correct or not.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing three integers nmK (1 ≤ n, m, K ≤ 30). Each of the next nlines contains K space separated integers where the ith line denotes the wishes of the ith person. Each of the integers in a line will be either positive or negative. Positive means the person wants the object in the solution; negative means the person doesn't want that in the solution. You can assume that the absolute value of each of the integers will lie between 1 and m.

The next line contains an integer p (0 ≤ p ≤ m) denoting the number of integers in the solution, followed byp space separated integers each between 1 and m, denoting the solution. That means the objects we have taken as solution set.

Output

For each case, print the case number and 'Yes' if the solution is valid or 'No' otherwise.

Sample Input

2

3 4 2

+1 -2

+3 +4

-3 -1

1 4

1 5 3

+1 -2 +4

2 2 5

Sample Output

Case 1: Yes

Case 2: No

题解:n个人找对象,对象从1--m,负数代表不要,正数代表要;现在给一组数,问是否满足所有人的意愿;

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
int mp[][]; int vis[];
int p;
int n, m, k;
set<int>st;
bool js(){
for(int i = ; i <= n; i++){
int flot = ;
for(int j = ; j <= k; j++){
if(st.count(mp[i][j])){
flot = ;
break;
}
}
if(!flot)return false;
}
return true;
}
int main(){
int T, kase = ;
scanf("%d", &T);
while(T--){
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i <= n; i++){
for(int j = ; j <= k; j++){
scanf("%d", &mp[i][j]);
}
}
scanf("%d", &p);
st.clear();
memset(vis, , sizeof(vis));
int x;
for(int i = ; i <= p; i++){
scanf("%d", &x);
st.insert(x);
vis[x] = ;
}
for(int i = ; i<= m; i++){
if(!vis[i])st.insert(-i);
}
if(js())printf("Case %d: Yes\n", ++kase);
else
printf("Case %d: No\n", ++kase);
}
return ;
}

Beauty of Array(模拟)的更多相关文章

  1. DP ZOJ 3872 Beauty of Array

    题目传送门 /* DP:dp 表示当前输入的x前的包含x的子序列的和, 求和方法是找到之前出现x的位置(a[x])的区间内的子序列: sum 表示当前输入x前的所有和: a[x] 表示id: 详细解释 ...

  2. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...

  3. 第十二届浙江省大学生程序设计大赛-Beauty of Array 分类: 比赛 2015-06-26 14:27 12人阅读 评论(0) 收藏

    Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...

  4. ZOJ 3872 Beauty of Array

    /** Author: Oliver ProblemId: ZOJ 3872 Beauty of Array */ /* 需求: 求beauty sum,所谓的beauty要求如下: 1·给你一个集合 ...

  5. Beauty of Array(思维)

    Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integ ...

  6. 2015 浙江省赛 Beauty of Array (思维题)

    Beauty of Array Edward has an array A with N integers. He defines the beauty of an array as the summ ...

  7. ZOJ 3872: Beauty of Array(思维)

    Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...

  8. PHP用Array模拟枚举

    C#中枚举Enum的写法: /// <summary> /// 公开类型 2-好友可见 1-公开 0-不公开 /// </summary> public enum OpenSt ...

  9. Beauty of Array

    Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...

随机推荐

  1. iOS开发-Runtime详解(简书)

    简介 Runtime 又叫运行时,是一套底层的 C 语言 API,其为 iOS 内部的核心之一,我们平时编写的 OC 代码,底层都是基于它来实现的.比如: [receiver message]; // ...

  2. Cookie知识点小结

    问题是什么?有哪些技术?如何解决? 1. Cookie 1)完成回话跟踪的一种机制:采用的是在客户端保存Http状态信息的方案 2)Cookie是在浏览器访问WEB服务器的某个资源时,由WEB服务器在 ...

  3. Rotate It !!(思维)

    Rotate It !! Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  4. kaggle之数字序列预测

    数字序列预测 Github地址 Kaggle地址 # -*- coding: UTF-8 -*- %matplotlib inline import pandas as pd import strin ...

  5. 10. 混淆矩阵、总体分类精度、Kappa系数

    一.前言 表征分类精度的指标有很多,其中最常用的就是利用混淆矩阵.总体分类精度以及Kappa系数. 其中混淆矩阵能够很清楚的看到每个地物正确分类的个数以及被错分的类别和个数.但是,混淆矩阵并不能一眼就 ...

  6. ERROR 1130: Host is not allowed to connect to this MySQL server

    解决远程连接mysql错误1130代码的方法 今天在用远程连接Mysql服务器的数据库,不管怎么弄都是连接不到,错误代码是1130,ERROR 1130: Host 192.168.2.159 is ...

  7. MySQL 触发器的定义

    -- Insert DELIMITER $$ USE `testdatabase`$$ DROP TRIGGER /*!50032 IF EXISTS */ `Trigger_XXX_INSERT`$ ...

  8. 前端--关于javascript对象

    在javascript中对象是一种基本的数据类型,在数据结构上是一种散列表,可以看作是属性的无序集合,除了原始值其他一切都是对象.它可以用来表示现实世界中或者我们大脑中抽象出来的客体,这和其他面向对象 ...

  9. mvc PagerHelper静态分页

    ---------------分页方法----------------- public static class PagerHelper    {        /// <summary> ...

  10. Unity脚本——Csharp

    打印输出: Debug.Log(""); 游戏流程函数: Awake():在对象被创建的时候调用. Start():在Awake()方法之后执行.在脚本禁用后不会执行. updat ...