/****************************************************************************************************
无聊死了。。。
****************************************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
//#include <hash_map> //Visual C++ lib
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <utility>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) )
#define CLR(x, k) memset((x), (k), sizeof(x))
#define CPY(t, s) memcpy((t), (s), sizeof(s))
#define SC(t, s) static_cast<t>(s)
#define LEN(s) static_cast<int>( strlen((s)) )
#define SZ(s) static_cast<int>( (s).size() )
typedef double LF;
//typedef long long LL; //GNU C++
//typedef unsigned long long ULL;
typedef __int64 LL; //Visual C++ 2010
typedef unsigned __int64 ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
//typedef hash_map<int, int>::iterator HMI;
typedef map<int, int>::iterator MI;
typedef vector<int>::iterator VI;
typedef list<int>::iterator LI;
typedef set<int>::iterator SI;
template <typename T>
T sqa(const T &x)
{
return x * x;
}
const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffffLL; //15f
const double oo = 10e9;
const double eps = 10e-9;
const double PI = acos(-1.0);
const int MAXV = 28;
const int MAXN = 10004;
int test, n, k, m;
int lack;
int lx[MAXV], ly[MAXV], match[MAXV], maze[MAXV][MAXV];
bool visx[MAXV], visy[MAXV];
char tec[MAXN];
bool dfs(const int &x)
{
visx[x] = true;
for (int y = 0; y < 26; ++y)
{
if (visy[y])
{
continue ;
}
int t = lx[x] + ly[y] - maze[x][y];
if (0 == t)
{
visy[y] = true;
if (-1 == match[y] || dfs(match[y]))
{
match[y] = x;
return true;
}
}
else if (lack > t)
{
lack = t;
}
}
return false;
}
int KM()
{
CLR(lx, 0);
CLR(ly, 0);
CLR(match, -1);
for (int i = 0; i < 26; ++i)
{
for (int j = 0; j < 26; ++j)
{
lx[i] = max(lx[i], maze[i][j]);
}
}
for (int x = 0; x < 26; ++x)
{
while (true)
{
CLR(visx, false);
CLR(visy, false);
lack = INF_INT;
if ( dfs(x) )
{
break ;
}
for (int i = 0; i < 26; ++i)
{
if (visx[i])
{
lx[i] -= lack;
}
if (visy[i])
{
ly[i] += lack;
}
}
}
}
int res = 0;
for (int i = 0; i < 26; ++i)
{
res += maze[ match[i] ][i];
}
return res;
}
void ace()
{
char ch;
for (cin >> test; test--; )
{
cin >> n >> k >> m;
for (int i = 0; i < n; ++i)
{
cin >> ch;
tec[i] = ch;
}
while (m--)
{
CLR(maze, 0);
for (int i = 0; i < n; ++i)
{
cin >> ch;
++maze[ tec[i] - 'A' ][ ch - 'A' ];
}
printf("%.4lf\n", KM() * 1.0 / n);
}
}
return ;
}
int main()
{
ace();
return 0;
}相关推荐
candence layout快捷键
摁住鼠标左键再框选:选中 摁住鼠标右键再框选:放大 选中之后,滚动鼠标滚轮进行放大缩小。 F:回到全局 shift+V:缩小 键盘的箭头:移动视图 F1:显示帮助文档Candence help F2:保存 点击r,画出矩形时不双击鼠标,点击F3,可以设置尺寸。 Creat-Shape-Path Creat-Wiring-Bus:画多根线。F3设置线宽、间距等。 选中金属后,Shift+G画保护环guard ring。F3可以设置距离金属的间距、保护环的形状。 Path和Rectang
三分查找
已知左右端点L,R,求顶点(极值)的位置。 思路通过不断缩小 [L,R] 的范围,无限逼近白点。 做法:先取 [L,R] 的中点 mid,再取 [mid,R] 的中点 mmid,通过比较 f(mid) 与 f(mmid) 的大小来缩小范围 当最后 L=R-1 时,再比较下这两个点的值,我们就找到了答案 1、当 f(mid) > f(mmid) 的时候,我们可以断定 mmid 一定在白...
从零到一:IC Compiler II(ICC II)后端设计流程详解
本文详细解析了IC Compiler II(ICC II)后端设计流程,从环境准备到物理实现,再到布线优化与签核验证。通过实战案例和高效技巧,帮助工程师掌握ICC II工具链的应用,提升数字集成电路设计的效率和质量。
HDU 3714 几何+三分法求凹曲线顶点
/**************************************************************************************************** 第一次写三分~居然是拿regional题练的。。。 ********************************************************************
基于N32G003的PMBus从机协议栈设计与STM32F103模拟I2C主机通信实战
本文详细介绍了基于N32G003微控制器设计PMBus从机协议栈,并与STM32F103模拟I2C主机进行通信的实战方案。重点阐述了中断驱动架构、命令解析、CRC8优化及超时恢复机制,实现了在70kHz速率下稳定可靠的工业电源管理通信,适用于服务器电源、通信基站等成本敏感应用场景。
机器学习——Anaconda下载安装教程
Anaconda详细下载安装教程
HDU3718 Similarity KM
原文链接http://www.cnblogs.com/zhouzhendong/p/8284763.html 题目传送门 - HDU3718 题意概括 直接描述输入吧 首先一个T(T<15),表示数据组数。 每组数据,首先三个数:len,k,m,分别表示接下来要读入的字符串的长度、每一个字符串中出现的不同字母个种类数、询问的字符串数。(len<=10000...
沙猫群优化算法(SCSO)详解:从沙漠生存智慧到全局优化引擎
本文详细介绍了沙猫群优化算法(SCSO),这是一种新型元启发式优化算法,灵感来源于沙猫在沙漠环境中的卓越狩猎行为。SCSO通过模拟沙猫的低频探测能力和精确攻击策略,将优化问题转化为搜索和捕获"猎物"的过程。算法核心包括探索阶段(全局搜索)和开发阶段(局部精细搜索),通过灵敏度范围模型和自适应控制参数实现两者的平衡。SCSO具有参数简单、收敛性能好等优点,适用于解决复杂全局优化问题。
HDU 3718 Similarity(KM最大匹配)
HDU 3718 Similarity 题目链接 题意:给定一个标准答案字符串,然后下面每一行给一个串,要求把字符一种对应一种,要求匹配尽量多 思路:显然的KM最大匹配问题,位置对应的字符连边权值+1 代码: #include #include #include #include using namespace std; const int MAXNODE
Spring Boot:如何快速搭建一个高性能微服务架构?
通过本文的详细步骤,我们成功搭建了一个高性能的微服务架构。Spring Boot 和 Spring Cloud 提供了强大的工具链,使得开发者能够快速实现服务注册与发现、负载均衡、熔断器与降级机制等功能。同时,通过数据库连接池、Redis 缓存和异步处理等优化手段,进一步提升了系统的性能和可靠性。希望本文能够帮助你快速入门 Spring Boot 微服务架构的搭建,并为实际项目提供参考。如果你有任何问题或建议,欢迎在评论区留言!
Agent智能体:核心概念与架构——建立系统认知
本文摘要介绍了Agent智能体的核心概念与架构设计。主要内容包括: Agent定义与分类:阐述了Agent作为能够感知环境、决策执行的智能实体,重点分析了现代基于大语言模型(LLM)的Agent架构。 核心模块组成:详细说明了Agent的五大核心模块(感知、规划、记忆、工具和执行)及其交互流程。 UML建模展示:通过类图和序列图,清晰呈现了Agent系统的静态结构和动态执行过程。 项目结构设计:给出了模块化的代码目录结构,为实际开发提供参考框架。
Hdu 3718(KM算法)
Hdu 3718 (1)题意: 给出一个长度为n的字符序列,字符序列是由‘A’~‘Z’组成的, 先给出一个标准的字符序列,表示正确答案的顺序,其中不同的字符数量为k。 接下来给出m个字符序列,每个字符序列长度为n, 每个字符序列中的不同字符数量不大于k,其中的字符与正确序列的字符可能不一样, 请问如果将询问序列中的字符与正确序列中的字符匹配,才能使正确率更高。 输出每个询问字符...
把 sy-* 带进 ABAP CDS:ABAP 7.50 里的环境信息新姿势($session 与 @Environment.systemField 实战)
摘要:ABAP 7.50在CDS视图中引入两种获取环境信息的方式:1)直接使用$session会话变量读取用户、客户端和系统语言;2)通过@Environment.systemField注解参数,由Open SQL自动注入系统字段。$session方式简单但依赖Open SQL访问路径,非ABAP环境下可能失效;注解参数方案更工程化,依赖关系明确且支持测试。建议ABAP体系内优先使用$session,对外接口采用参数化方案。两种方式各有适用场景,正确选择可避免潜在风险。(148字)
hdu 2426 hdu 3718 二分图最优匹配算法KM
偶然间做到2426题,发现是二分图最优匹配,,以前一直没看过,于是就学习了下KM算法。 上网搜的课件发现都是同一个版本。。。木办法了,只有硬着头去看了。 看了两天,终于略有一点收获。。 hdu 2426:http://acm.hdu.edu.cn/showproblem.php?pid=2426 需要注意一点负权直接舍弃。 代码虽然AC了,但是对于这样的例子一直没能通过 2 1 2 ...
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
android 蓝牙通讯demo
android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。
hdu 3718 KM最优匹配
建图过程,上面一行字母与下面一行一一对应连边,再利用KM求一个最优匹配即可 #include #include #include #include #include using namespace std; #define MIN(a,b) a<b?a:b #define INF 999999 #define MAX 50 int match[MAX]; bool sx[
温度PID控制PLC程序
温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值
HDU 3718 KM算法
题意:给你一个模板串,在给你m个串
HDU 3718 Similarity
HDU 3718 Similarity km最优匹配(百度) 建图的时候对应位置的边权值加一(最后建出来的图是[A-Z]->[A-Z],而不是字符串位置对应字符串位置),km匹配完之后把匹配成功的边的权值加起来除以n就是答案。 代码: #include <iostream> #include <cstring> #include <cstdio> #inc...
Similarity 【HDU - 3718】【KM算法】
题目链接 题意: 有T次查询,每次给出一个长度为N的基础串,以及分别给出M个同样长度为N的待查询串,我们现在想知道,对应的交换顺序之后的使得它们可以成映像关系的最大的长度比上总长度的值为多少。 思路: 关于这道题的N是很大,但是由于K只有上限26,所以突破口在于这个K,我想让最多的匹配上,也就是匹配上的权值是最大的,这里该怎么办呢?于是就可以建立mp[27][27],对应每...
HDU 3718 Similarity【KM算法】
题目链接 题意:两串字母匹配,求最大权匹配除以长度。 二分图最大权匹配KM算法模板题。 #include #include #include #include #include using namespace std; const int maxn = 'Z' + 10; const int INF = 0x3f3f3f3f; //接口:KM() //输入:w[][] 全局
HDU 3718 Similarity(KM算法)
把对应位置的字母边练起来,权值加一,最后求二分图最大权值即可。#include #include using namespace std; const int maxn=30+5; int w[maxn][maxn],n,m; int lx[maxn],ly[maxn]; int Left[maxn]; bool s[maxn],t[maxn]; char ss[35][20005]; char
hdu - 3718 二分图最佳匹配 KM算法
题意:有两串字符串,他们都是分类的结果.第一行是正确结果,第二行是需要你判断的.比如:A A B A B B C C C CS T R S T R S T R S 当S对应A,T对应B,R对应C时, 它们匹配的位置个数=4 当S对应C,T对应A,B对应R时, 它们匹配的位置个数=5 明显第二种匹配方式更好,字符串相似率达到了5/10=50%. 现在...
hdu 3718 Similarity【KM匹配】
Similarity Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1915 Accepted Submission(s): 776 Problem Description When we were childre
HDU 3718 Similarity KM算法
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3718 题意:给定一个字符串,然后输入m串字符串,使字符串中字符匹配数量最大,输出匹配量 / 字符串长度 思路:对于每对对应字符建边,权值加1,然后求最大匹配权值即可 总结:刚开始看貌似很难,在纸上画了两下,就有了思路,不小心水了过去~~~ #include #include #include
hdu3718Similarity KM算法
//n个物品,用字母表示每个物品的种类, //给出标准答案对于每种物品的字母表示 //给出每个人的答案,问怎样的匹配使得两个答案的相似度更高 //{A A B A B B C C C C},{F F E F E E D D D D}表示一种答案 //对每个字母和字母之间建图,两个答案在同一个位置的字母之间的边的权值加1 //那么就只需要求其最大带权匹配 #include<cstdio> #inclu
HDU3718Similarity(KM最大匹配)
题意:就是学生对一类物品的分类。与标准答案之间的相似度。 思路:按题目的公式,对应位置连边。边出现的次数就是权重,计算KM 开始用getchar()读入结果悲剧的TLE 了。然后换成了%S读入,140ms。这是为什么额 #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<set> #in
hdu 3718 Similarity (二分图KM算法)
解题思路:二分图。 建图:将学生的答案所映射的正确答案作为二分图的边,边权值为1,有两条就为2,依此类推。 然后用KM算法求出最佳匹配。除以n 就是要求的答案了。 #include #include #include using namespace std; #define N 101 #define MIN -0xfffffff #define MAX 0xfffffff #
2655



被折叠的 条评论
为什么被折叠?



