Go Deeper

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 21 Accepted Submission(s): 10
 
Problem Description
Here is a procedure's pseudocode:

go(int dep, int n, int m)
begin
output the value of dep.
if dep < m and x[a[dep]] + x[b[dep]] != c[dep] then go(dep + 1, n, m)
end

In this code n is an integer. a, b, c and x are 4 arrays of integers. The index of array always starts from 0. Array a and b consist of non-negative integers smaller than n. Array x consists of only 0 and 1. Array c consists of only 0, 1 and 2. The lengths of array a, b and c are m while the length of array x is n. Given the elements of array a, b, and c, when we call the procedure go(0, n, m) what is the maximal possible value the procedure may output?

 
Input
There are multiple test cases. The first line of input is an integer T (0 < T ≤ 100), indicating the number of test cases. Then T test cases follow. Each case starts with a line of 2 integers n and m (0 < n ≤ 200, 0 < m ≤ 10000). Then m lines of 3 integers follow. The i-th(1 ≤ i ≤ m) line of them are ai-1 ,bi-1 and ci-1 (0 ≤ ai-1, bi-1 < n, 0 ≤ ci-1 ≤ 2).
 
Output
For each test case, output the result in a single line.
 
Sample Input
3
2 1
0 1 0
2 1
0 0 0
2 2
0 1 0
1 1 2
 
Sample Output
1
1
2
 
Author
CAO, Peng
 
Source
The 2010 ACM-ICPC Asia Chengdu Regional Contest
 
Recommend
zhouzeyong
 
/*
题意:给出递归函数:
void go(int dep, int n, int m){
printf("%d\n",dep);
if(dep<m&&x[a[dep]]+x[b[dep]]!=c[dep])
go(dep + 1, n, m);
}
其中,a,b数组的元素小于n 数组长度为m,c数组的元素只有 0,1,2 数组长度为m, x数组的元素只有0,1现在给出a,b,c
数组的元素,问你这个输出的dep最大是多少,也就是递归最多的次数。 初步思路:分析条件:dep<m&&x[a[dep]]+x[b[dep]]!=c[dep] m是最大可能的递归次数,并且x[a[dep]]+x[b[dep]]!=c[dep]
实际上是x[a[dep]]+x[b[dep]]和c[dep]是不能共存的,也就是说有如下几种情况:
c[dep]==0:x[a[dep]]和x[b[dep]],必定至少有一个为真
c[dep]==1:x[a[dep]]和x[b[dep]],只能都为真都为假
c[dep]==2:x[a[dep]]和x[b[dep]],不能都为真
由上面三种情况,二分递归的次数,判断的规则就是2-SAT跑的结果
*/
#include<bits/stdc++.h>
using namespace std;
int t;
int n,m;
int a[],b[],c[],x[];
/*********************************************2-SAT模板*********************************************/
const int maxn=+;
struct TwoSAT
{
int n;//原始图的节点数(未翻倍)
vector<int> G[maxn*];//G[i].j表示如果mark[i]=true,那么mark[j]也要=true
bool mark[maxn*];//标记
int S[maxn*],c;//S和c用来记录一次dfs遍历的所有节点编号 //从x执行dfs遍历,途径的所有点都标记
//如果不能标记,那么返回false
bool dfs(int x)
{
if(mark[x^]) return false;//这两句的位置不能调换
if(mark[x]) return true;
mark[x]=true;
S[c++]=x;
for(int i=;i<G[x].size();i++)
if(!dfs(G[x][i])) return false;
return true;
} void init(int n)
{
this->n=n;
for(int i=;i<*n;i++)
G[i].clear();
memset(mark,,sizeof(mark));
} //加入(x,xval)或(y,yval)条件
//xval=0表示假,yval=1表示真
void add_clause(int x,int xval,int y,int yval)//这个地方不是一尘不变的,而是参照问题的约束条件进行加边
{
G[*x+xval].push_back(y*+yval);
} //判断当前2-SAT问题是否有解
bool solve()
{
for(int i=;i<*n;i+=)
if(!mark[i] && !mark[i+])
{
c=;
if(!dfs(i))
{
while(c>) mark[S[--c]]=false;
if(!dfs(i+)) return false;
}
}
return true;
}
}TS;
/*********************************************2-SAT模板*********************************************/
void build(int mid){
TS.init(n);
for(int i=;i<mid;i++){
switch(c[i]){
case :
TS.add_clause(a[i],,b[i],);
TS.add_clause(b[i],,a[i],);
break;//不能都为假
case :
TS.add_clause(a[i],,b[i],);
TS.add_clause(b[i],,a[i],);
TS.add_clause(a[i],,b[i],);
TS.add_clause(b[i],,a[i],);
break;//同真同假
case :
TS.add_clause(a[i],,b[i],);
TS.add_clause(b[i],,a[i],);
break;//不能同真
}
}
}
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i=;i<m;i++){
scanf("%d%d%d",&a[i],&b[i],&c[i]);
}
int l=,r=m;
while(l<=r){
int mid=(l+r)/;
build(mid);
if(TS.solve()==true) l=mid+;
else r=mid-;
}
printf("%d\n",l-);
}
return ;
}

Go Deeper的更多相关文章

  1. Go Deeper(2010成都现场赛题)(2-sat)

    G - Go Deeper Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description ...

  2. 解读(GoogLeNet)Going deeper with convolutions

    (GoogLeNet)Going deeper with convolutions Inception结构 目前最直接提升DNN效果的方法是increasing their size,这里的size包 ...

  3. HDU 3715 Go Deeper(2-sat)

    HDU 3715 Go Deeper 题目链接 题意:依据题意那个函数,构造x数组.问最大能递归层数 思路:转化为2-sat问题,因为x仅仅能是0.1,c仅仅能是0,1.2那么问题就好办了,对于0, ...

  4. 论文阅读笔记四十二:Going deeper with convolutions (Inception V1 CVPR2014 )

    论文原址:https://arxiv.org/pdf/1409.4842.pdf 代码连接:https://github.com/titu1994/Inception-v4(包含v1,v2,v4)   ...

  5. 论文笔记:Deeper and Wider Siamese Networks for Real-Time Visual Tracking

    Deeper and Wider Siamese Networks for Real-Time Visual TrackingUpdated on 2019-04-01 16:10:37 Paper ...

  6. Go Deeper HDU - 3715(2 - sat 水题 妈的 智障)

    Go Deeper Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  7. 图像分类(一)GoogLenet Inception_V1:Going deeper with convolutions

    论文地址 在该论文中作者提出了一种被称为Inception Network的深度卷积神经网络,它由若干个Inception modules堆叠而成.Inception的主要特点是它能提高网络中计算资源 ...

  8. 【ML】ICLR2016_Delving Deeper into Convolutional Networks

    ICLR2016_DELVING DEEPER INTO CONVOLUTIONAL NETWORKS Note here: Ballas recently proposed a novel fram ...

  9. Going deeper with convolutions 这篇论文

    致网友:如果你不小心检索到了这篇文章,请不要看,因为很烂.写下来用于作为我的笔记. 2014年,在LSVRC14(large-Scale Visual Recognition Challenge)中, ...

随机推荐

  1. [SDOI2009]HH的项链解题报告

    原题目:洛谷P1972 题目描述 HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH 不断地收集新的贝壳,因此 ...

  2. 修改NSMutableArray中的元素时的注意事项

    最近做项目遇到从文件加载数组,并对数组中的元素进行操作的问题,特意写了个Demo,记录下要注意的东西: 代码如下: NSArray *array = @["]; NSMutableArray ...

  3. SVG轨迹回放实践

    最近做了埋点方案XTracker的轨迹回放功能,大致效果就是,在指定几个顺序的点之间形成轨迹,来模拟用户在页面上的先后行为(比如一个用户先点了啥,后点了啥).效果图如下: 在这篇文章中,我们来聊聊轨迹 ...

  4. Query DSL(1)

    https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl.html Query DSL GET _search { & ...

  5. Linux入门之常用命令(5)Bash

    bash优点 1.命令编辑能力  记录使用过的命令 ~/.bash_history 记录上次的历史命令 2.补全功能  指令补全两下tab 文件名补全 3.命令别名  alias [别名]=‘’ 4. ...

  6. VC维含义的个人理解

    有关于VC维可以在很多机器学习的理论中见到,它是一个重要的概念.在读<神经网络原理>的时候对一个实例不是很明白,通过这段时间观看斯坦福的机器学习公开课及相关补充材料,又参考了一些网络上的资 ...

  7. WordPress-基础设置之常规设置

    对于第一次使用Wordpress系统的朋友,请先别着急发布文章及进行其他操作,为了更加科学的使用及管理wordpress,应该需要对其进行相关设置,主要涉及3个部分,一.常规设置,二.阅读设置,三.固 ...

  8. 多个activity跳转保留内存使用intent传递数据问题_新手

    /////本来是做的activity跳转,普通那种,但是会在调回来会销毁原来的,重新调用onCreate方法, 后来参考[http://blog.csdn.net/qq_26918031/articl ...

  9. “一切都是消息”--MSF(消息服务框架)之【发布-订阅】模式

    在上一篇,“一切都是消息”--MSF(消息服务框架)之[请求-响应]模式 ,我们演示了MSF实现简单的请求-响应模式的示例,今天来看看如何实现[发布-订阅]模式.简单来说,该模式的工作过程是: 客户端 ...

  10. Spring事务管理配置示例

    (一).Spring事务特性 1.事务隔离级别 隔离级别是指若干个并发的事务之间的隔离程度. ISOLATION_DEFAULT:默认值,使用数据库的默认隔离级别,就是ISOLATION_READ_C ...