hdu4685 Prince and Princess(tarjan强连通分量+二分图匹配)

adas硬件_ADAS智能辅助驾驶系统硬件在环(HIL)测试之硬件介绍 这篇主要分享的是ADAS融合系统的HIL测试系统的硬件结构及其作用,其主要包括上位机、机柜、雷达模拟器系统、雷达暗箱系统以及视频暗箱。 上位机 上位机主要运行HIL测试系统的相关软件,测试人员所有的前期准备工作与测试操作均在上面进行,并监控测试结果,其通过网口实现与NI实时机的通信,上位机将VeriStand项目工程下载至NI实时机运行。机柜 机柜主要由可编程电源... 阅读详情

思路来源

https://blog.csdn.net/sdj222555/article/details/9990131

预备题目

poj1904 King's Quest

n个(n<=2000)王子,n个公主,

已知第i个王子喜欢ki个公主,以下给出k个数代表各个公主编号

最后给出一种完美匹配,代表第j个公主最终选择了哪个王子

要求求出每个王子的可能喜欢的公主集合,使得王子选这个集合里的任意一个公主

都存在方式能达到完美匹配,依次输出第i个王子的公主集合编号,集合内按增序输出

预备题目题解

王子向自己喜欢的公主连边,在完美匹配中公主选择了哪个王子就向哪个王子连边,

不妨把一对夫妻看作一个点缩点,那么,夫妻A和B能换妻当且仅当A的夫指向B的妻,且B的夫指向A的妻

也就是,在新的缩点后的图里,A和B还位于同一个强连通分量里,

由于强连通分量具有类似的传递性,

即A和B位于一个强连通分量里,B和C位于一个强连通分量里,那么ABC一定在一个强连通分量里

只需要求一次强连通分量,去判断和王子在相同的强连通分量里,有哪几个公主,输出即可

预备题目代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const int N=2e3+5;
const int M=2e5+1e4;//2e5+2e3 
int head[N*2],cnt;
int low[N*2],dfn[N*2],stack[N*2],par[N*2],num,now,top,tot;
bool In[N*2]; 
int n,k,v,len;
struct edge{int to,next;}e[M];
vector<int>ans;
int Scan()     //输入外挂
{
    int res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
void Out(int a)    //输出外挂
{
    if(a>9)
        Out(a/10);
    putchar(a%10+'0');
}
void init()
{
	memset(head,0,sizeof head);
	memset(In,0,sizeof In);
	memset(low,0,sizeof low);
	memset(dfn,0,sizeof dfn);
	memset(par,0,sizeof par);
	cnt=num=top=tot=0;
}
void add(int u,int v)
{
	e[++cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}
void dfs(int u)
{
	low[u]=dfn[u]=++num;
	In[u]=1;
	stack[++top]=u;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].to;
		if(!dfn[v])
		{
			dfs(v);
			low[u]=min(low[u],low[v]);
		}
		else if(In[v])
		{
			low[u]=min(low[u],dfn[v]);
		}
	}
	if(low[u]==dfn[u])//环的第一个点 
	{
		tot++;
		do
		{
			now=stack[top--];
			par[now]=tot;
			In[now]=0;
		}while(now!=u);
	}
}
int main()
{
	while(~scanf("%d",&n))
	{
		init();
		for(int i=1;i<=n;++i)
		{
			k=Scan();
			for(int j=1;j<=k;++j)
			{
				v=Scan();
				add(i,v+n);
			}
		}
		for(int i=1;i<=n;++i)
		{
			v=Scan();
			add(v+n,i);
		}
		for(int i=1;i<=n;++i)
		if(!dfn[i])dfs(i);
		for(int u=1;u<=n;++u)
		{
			for(int i=head[u];i;i=e[i].next)
			{
				int v=e[i].to;
				if(par[u]==par[v])
				ans.push_back(v-n); 
			}
			sort(ans.begin(),ans.end());
			len=ans.size();
			Out(len);
			for(int i=0;i<len;i++)
			putchar(' '),Out(ans[i]);
			ans.clear();
			puts("");
		}
	}
	return 0;
}

题目

n(n<=500)个王子,m(m<=500)个公主,n、m未必相等

已知第i个王子喜欢ki个公主,以下给出k个数代表各个公主编号,并不给出最大匹配

要求求出每个王子的可能喜欢的公主集合,使得王子选这个集合里的任意一个公主

都存在方式能达到完美匹配,依次输出第i个王子的公主集合编号,集合内按增序输出

题解

考虑类似poj1904的做法,先求出最大匹配,hungary中dfs的时候cx[]cy[]记录一下两边具体连了谁

cx[i]记录第i个王子选择了哪个公主,cy[j]记录了第j个公主选择了哪个王子

求得一种匹配方案,然后在这种方案里把cx[i]向i连边

考虑没有被匹配的王子cx[k],对每个cx[k]都建一个虚拟公主,使之被cx[k]匹配,且被所有王子喜欢

同理,考虑所有没被匹配的公主cy[l],对每个cy[l]都建一个虚拟王子,使之被cy[l]匹配,且喜欢所有公主

这样如果最大匹配个数为x,没被匹配上的王子为n-x,没被匹配上的公主为m-x

虚拟王子就为m-x个,虚拟公主就为n-x个,总的王子和公主个数各为n+m-x个,

两边王子公主相等之后,再求一遍SCC,将实际存在的公主编号存入王子集合即可

感性理解一下,之所以可行,是王子1匹配了公主A,王子2匹配了虚拟公主B,

1、2、A、B位于同一强连通分量内,就相当于可等价为,王子1匹配了虚拟公主B,王子2匹配了A,二者可换

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const int N=1005;
const int M=N*N;//N*N+N 
int head[N*2],cnt;
int cx[N*2],cy[N*2];
int low[N*2],dfn[N*2],stack[N*2],par[N*2],num,now,top,tot;
bool In[N*2],vis[N*2]; 
int t,n,m,k,v,len,mx,all;
struct edge{int to,next;}e[M];
vector<int>ans;
void init()
{
	memset(head,0,sizeof head);
	memset(In,0,sizeof In);
	memset(low,0,sizeof low);
	memset(dfn,0,sizeof dfn);
	memset(par,0,sizeof par);
	cnt=num=top=tot=0;
}
void add(int u,int v)
{
	e[++cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}
void tarjan(int u)
{
	low[u]=dfn[u]=++num;
	In[u]=1;
	stack[++top]=u;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].to;
		if(!dfn[v])
		{
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(In[v])
		{
			low[u]=min(low[u],dfn[v]);
		}
	}
	if(low[u]==dfn[u])//环的第一个点 
	{
		tot++;
		do
		{
			now=stack[top--];
			par[now]=tot;
			In[now]=0;
		}while(now!=u);
	}
}
bool dfs(int u)
{
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].to;
		if(!vis[v])
		{
			vis[v]=1;
			if(cy[v]==-1||dfs(cy[v]))
			{
				cx[u]=v;
				cy[v]=u;
				return 1;
			}
		}
	}
	return 0;
}
int hungary()
{
	int res=0;
	memset(vis,0,sizeof vis);
	memset(cx,-1,sizeof cx);
	memset(cy,-1,sizeof cy);
	for(int i=1;i<=n;++i)
	{
		memset(vis,0,sizeof vis);
		res+=dfs(i);
	}
	return res;
}
int main()
{
	scanf("%d",&t);
	for(int cas=1;cas<=t;++cas)
	{
		scanf("%d%d",&n,&m);
		mx=max(n,m);
		init();
		for(int i=1;i<=n;++i)
		{
			scanf("%d",&k);
			for(int j=1;j<=k;++j)
			{
				scanf("%d",&v);
				add(i,v+mx);
			}
		}
		hungary();
		for(int i=1;i<=n;++i)
		if(~cx[i])add(cx[i],i);//存在最大匹配
		all=2*mx;//[1,mx][mx+1,2*mx]是实际的王子 公主 
		for(int i=1;i<=n;++i)
		{
			if(~cx[i])continue;
			all++;//虚拟公主 被所有人喜欢 匹配给没有公主的王子 
			for(int j=1;j<=n;++j)
			add(j,all);
			cx[i]=all;cy[all]=i;add(all,i);
		} 
		for(int i=mx+1;i<=mx+m;++i)
		{
			if(~cy[i])continue;
			all++;//虚拟王子 喜欢所有公主 匹配给没有王子的公主
			for(int j=mx+1;j<=mx+m;++j)
			add(all,j);
			cx[all]=i;cy[i]=all;add(i,all); 
		} 
		for(int i=1;i<=all;++i)
		if(!dfn[i])tarjan(i);
		printf("Case #%d:\n",cas);
		for(int u=1;u<=n;++u)
		{
			for(int i=head[u];i;i=e[i].next)
			{
				int v=e[i].to;
				if(par[u]==par[v]&&v<=2*mx) 
				ans.push_back(v-mx); 
			}
			sort(ans.begin(),ans.end());
			len=ans.size();
			printf("%d",len);
			for(int i=0;i<len;i++)
			printf(" %d",ans[i]);
			ans.clear();
			puts("");
		}
	}
	return 0;
}

 

工业缺陷标注要人命?我从零搭了一套自动标注系统,标注效率直接提升10倍 你是不是也深陷工业缺陷标注的无尽内耗?这不是个例,工业视觉项目落地,80%的时间和成本,都耗在了数据标注环节。普通的图像标注(猫狗分类、人脸识别),标注门槛低、规则简单、一致性要求宽松;而工业缺陷标注,是CV领域公认的地狱级难度:缺陷尺寸小到几像素、种类繁杂且非标、行业专业性极强、标注精度要求到像素级、正负样本极度不均衡,人工标注不仅效率低、成本高,更直接决定了模型的最终上限。我在工业视觉行业摸爬滚打了6年,踩遍了人工标注的所有坑,最终从零搭建了一套工业缺陷专用的闭环自动标注系统,把原来一张图30分钟的标注 阅读详情

相关推荐

YonSuite如何新增用户并分配角色角色授权图文教程

用友YonSuite产品基础教学

ct341688的博客 630

hdu 4685 简单匹配+Tarjan算法

思路:首先看到这题以为能用poj1904的模版直接A掉,WA了几次,然后又TLE了几次。还是想到了正解。 一开始我想的大致方向已经是对的了。先是由王子向每个喜欢的公主建边,再求一次最大匹配,找出匹配后,由匹配的公主向王子建边。 但可能会有没有匹配到的公主和王子,那么这个王子可以和任何它喜欢的公主结婚,这个公主也可以和任何喜欢她的王子结婚。 因为这些不在匹配中的点,加到匹配中后,减少的匹配数和...

weixin_30292745的博客 104

5G LDPC编码实战:从校验矩阵到Matlab代码实现(附完整源码)

本文深入解析5G NR标准中的LDPC编码工程实现,聚焦于从3GPP协议中的QC-LDPC校验矩阵到高效Matlab代码的转换。文章详细阐述了基础矩阵(BG1/BG2)选择、提升因子确定以及利用双对角结构的快速编码算法,并提供了完整的、可优化的Matlab源码,旨在帮助通信算法工程师和开发者快速构建5G LDPC编码仿真原型,为硬件实现奠定基础。

table的专栏 380

【强连通】 HDU 4685 Prince and Princess

点击打开链接 题意:n个王子,m个公主,配对。每个王子可以在给出的ki个公主中选一个结婚。。 求最大的配对情况下,配对的状态。 题解:最后的answer 肯定是一些公主之间的连通的状态。 二分匹配找到与王子配对的公主。 再对公主对应的王子对应的ki个公主建边,形成的连通图既是对应某个王子的能取的公主 #pragma comment(linker, "/STACK:1024000000,

Kewowlo 666

用Multisim和74HC系列芯片,手把手教你搭建一个能“算数”的简易CPU模型

本文详细介绍了如何使用Multisim仿真软件和74HC系列芯片搭建一个简易CPU模型,重点解析了74HC194寄存器和74HC283加法器的核心功能与连接方法。通过分步图解和实战调试,帮助读者理解CPU工作原理,掌握数字电路设计的基本技能,适合计算机组成原理初学者和电子爱好者实践学习。

weixin_26843605的博客 146

lisp方格网法计算土方量_分享:两期土方工程量计算(方格网法)实例例题

最近遇到一个飞时达土方软件试用版客户,咨询怎么根据平整前的原始地形图和平整后的现状地形图来计算产生的土方工程量,也就是两期土方量,且需要用方格网法来计算,作为一个老道的工程设计人员,博主对这类的项目实例例题简直太熟悉了,用飞时达土方计算软件V13.0可以很方便的计算出来。 方格网法计算两期土方量流程 一、软件安装及注册 专业的飞时达土方计算软件FastTFT,请到飞时达软件官方网站去下载,注册完...

weixin_35131425的博客 1706

Prince and Princess HDU - 4685(匹配 + 强连通)

Prince and Princess Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 2336Accepted Submission(s): 695 Problem Description There are n ...

babing2770的博客 227

【Codesys】获取从站信息,判断是否从站断联,总线丢失

获取EtherCAT从站信息,判断是否从站断联,总线丢失

qq_35316470的博客 5744

H - Prince and Princess HDU - 4685(强连通分量缩点+二分图匹配+奇怪建图)

H - Prince and Princess HDU - 4685(强连通分量缩点+二分图匹配+奇怪建图) 题目:传送门 思路见注释 代码 : /* 做法: 1.建图最大匹配 2.增加点,给不能匹配的匹配上 3.再次二分图匹配 4.对于u,匹配的match[u],那么match[u]连接所有对应u喜欢的顶点 5.强连通分量缩点. 6.对于u ,对于喜欢的公主v,如果v和match[u]颜色相同,...

Dch19990825的博客 296

33、AI赋能5G/6G通信:LDPC码解码与强化学习技术解析

本文探讨了基于AI和强化学习的LDPC码技术在5G/6G通信中的应用。包括LAMS解码器、神经MS解码器、盲识别方法、统一极性-LDPC解码器、NNMS和SNNMS解码器、N-2D-NMS解码器、神经分层MS解码器、MAB-NS方案以及强化学习与MCTS结合的技术。这些技术在提升解码性能、降低计算复杂度和增强系统适应性方面表现出色,为未来通信系统的发展提供了强有力的支持。

lambda的博客 248

PX4从放弃到精通(二十一):使用git管理PX4代码

文章目录前言一、设置git密钥二、将代码上传至gitee 前言 Ubuntu 18.04 PX4 1.11.3 由于github有时网速较慢,本文使用gitee。 一、设置git密钥 ssh-keygen -t rsa -C “your_email@youremail.com” your_email@youremail.com为自己注册的gitee账户邮箱.设置路径与密码时,也直接回车不设置,如下图,密钥生成的位置在红框处. 在密钥目录下按Ctrl+H显示隐藏文件,进入.ssh文件夹用gedit打开id

超维空间科技的博客 3482

HDU 4685 Prince and Princess (二分图匹配+强连通分量)

题意:有n个王子和m个公主,每个王子都有若干个喜欢的公主,王子需要娶喜欢的公主,一个王子只能娶一个公主。输出对于每个王子,他可以娶的公主的编号的集合。王子娶这个集合的任一个公主,其他王子与公主的最大匹配数不变。 题解:二分图匹配+强连通分量 对于题目要求王子娶集合任意公主,最大匹配都不变,我们可以想到强连通分量,我们在分量内放入等量的能够任意匹配的王子和公主,这样无论王子选哪一个,其他王子也有的选。 但是由于这题王子和公主的数量不等,我们可以引入虚拟结点,具体一点来说就是:在求完最大匹配后,对于未匹配的结点

gongyuandaye的博客 269

windows下玩转vllm:在wsl下安装vllm

当前,部署通义千问2.5-vl已经是一件箭在弦上,不得不发的事儿了。网上搜了一下,发现还是用vllm用的比较多。于是乎,这就开始尝试部署vllm。但是我们之前说了,vllm是不支持直接在windows上部署的,我们还得搞wsl或者docker。咱今天先尝试使用wsl进行安装哈。

xiezhipu的博客 4140

HDU 4685. Prince and Princess

链接 http://acm.hdu.edu.cn/showproblem.php?pid=4685 题意 nnn 个王子,mmm 个公主,每个王子可以娶他喜欢的公主中的一个,每个公主只能嫁个一个王子,必须保证最大匹配,升序输出每个王子可以娶的公主的编号 思路 先求二分图最大匹配,给两边未匹配的点添加虚点凑成完美匹配(虚点与另一边所有点之间都要加一条有向边) 然后在所有匹配的两点之间加一条反向边 最后求强连通分量,每个强连通分量中与王子直接相连的公主就是他可以娶的公主 代码 #include<bits/

c4Lnn 的 CSDN 博客 190

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

HDU - 4685 Prince and Princess (构造完美匹配+强连通分量)

链接:https://cn.vjudge.net/problem/HDU-4685 题意:T组样例。有n个王子和n个公主,每个王子都有若干个喜欢的公主,王子需要娶喜欢的公主,一个王子只能娶一个公主。输出对于每个王子,他可以娶的公主的编号的集合。王子娶这个集合的任一个公主,其他王子与公主的最大匹配数不变。 思路:这道题和poj1904https://blog.csdn.net/birdmanqi...

birdmanqin的博客 327

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

hdu4685Prince and Princess 二分图+Tarjan缩点

hdu4685Prince and Princess 题目传送门 分析 题目大意:一个王子喜欢好多妹子,现在要让最多的王子妹子双宿双飞,同时求出一个王子可以和多少个妹子结婚并且不影响别的王子妹子双宿双飞的对数。 很强的一道二分图,是poj1904的加强版本。 有一个正经的名字叫二分图匹配的可行边。 首先考虑完备匹配的情况。 一种很神仙的做法是,王子照样向妹子连边,但是如果某个妹子匹配了王子,把那个...

maxtir的博客 368

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU - 4685 Prince and Princess

There are n princes and m princesses. Princess can marry any prince. But prince can only marry the princess they DO love.  For all princes,give all the princesses that they love. So, there is a maxim

Ninaye的博客 487

Prince and Princess HDU - 4685

题意: 有 n 个王子和 m 个公主,每个王子有 kik_iki​ 个喜欢的公主,每个公主都喜欢所有的王子,询问每个王子可能会和哪些公主匹配。 题解: 首先 n 个王子 和 m 个公主做一次二分匹配,得到匹配数最大为res,相当于右边有 m - res 个点没有匹配,左边有 n - res 个点没有匹配。 所以可以加入 m - res 个王子喜欢所有的公主,加入 n - res 个公主被所有的王子喜欢,加入后的新图一定是一个完美匹配。 然后跑一次强连通 如果u,v属于同一连通块,那么相当于连通块中的王子公主

qq_43544481的博客 184

HDU 4685 Prince and Princess(二分匹配加点建图+强连通分量)

题目链接 Problem Description There are n princes and m princesses. Princess can marry any prince. But prince can only marry the princess they DO love. For all princes,give all the princesses that they lov...

Running Bit. 445

hdu 4685 Prince and Princess 【匈牙利算法-匹配、强连通分量-Tarjan-缩点】

Prince and Princess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Problem Description There are n princes and m princesses. Princess can marry any prince. But

逝去的时光 443

HDU-4685-Prince and Princess(二分匹配+强连通分量)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4685 POJ1904加强版本 大致题意: N个王子,N个妹子,每个王子喜欢N个妹子中的K个, 让求所有最大匹配每个王子解的集合。 题解: 问题主要在建边,设王子集合为X,妹纸集合为Y, 那么王子的选择为X->Y, 已知一组完美匹配方案X'->Y'

不会吃鱼的喵 505

POJ 1904 King's Quest && HDU 4685 Prince and Princess (强联通解决二分图可行匹配问题)

King's Quest Time Limit: 15000MS   Memory Limit: 65536K Total Submissions: 9427   Accepted: 3483 Case Time Limit: 2000MS Description Once upon a time there lived a

K键盘里的青春K 626

HDU 4685 Prince and Princess

题目 人题意: 有n个王子,m个公主,王子可以喜欢很多个公主,每个王子可以娶一个公主,每个公主可以嫁一个王子,这样可以得到一个最大匹配,对每个王子,求出他选择娶那些公主不影响到最大匹配。 解法: 一开始,想到的做法是所有的王子向其喜欢的公主连边,做一遍二分图后,每个公主向选择了她的王子连边,这样,如果某个王子喜欢的两个公主在同一个强联通分量里的话,说明这个强联通分量里面的边都能取反向,则同

Tri_integral的专栏 1221

hdu 4685 Prince and Princess (二分图匹配+tarjan)

There are n princes and m princesses. Princess can marry any prince. But prince can only marry the princess they DO love. For all princes,give all the princesses that they love. So, there is a maximum...

creator平 189

HDU 4685 Prince and Princess(二分图 + 强连通)

Problem Description There are n princes and m princesses. Princess can marry any prince. But prince can only marry the princess they DO love. For all princes,give all the princesses that they love.

左眼皮跳跳 793

HDU 4685 Prince and Princess(二分图匹配+强联通分量)

                                           Prince and Princess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 2078    Accepted Submission(s):...

shyoldman的博客 255
上一篇: hdu4738 Caocao's Bridges(Tarjan/双连通分量+桥+特判)
下一篇: 牛客小白月赛16 I.石头剪刀布(期望dp or 高斯消元)
小衣同学
博客等级 码龄9年 1444粉丝 995原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小衣同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址