hdu 1545 01-K Code

『杭电1545』01-K Code Problem Description Consider a code string S of N symbols, each symbol can only be 0 or 1. In any consecutive substring of S, the number of 0's differs from the number of 1's by at most K. How many such valid code strings S are there? For example, when N 阅读详情

01-K Code

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 406    Accepted Submission(s): 96


Problem Description
Consider a code string S of N symbols, each symbol can only be 0 or 1. In any consecutive substring of S, the number of 0's differs from the number of 1's by at most K. How many such valid code strings S are there? 

For example, when N is 4, and K is 3, there are two invalid codes: 0000 and 1111. 
 

Input
The input consists of several test cases. For each case, there are two positive integers N and K in a line.

N is in the range of [1, 62].

K is in the range of [2, 5].
 

Output
Output the number of valid code strings in a line for each case.
 

Sample Input
1 2 4 3
 

Sample Output
2 14
 


分析:dp[i][j][k] 表示遍历到第i位(从1开始),当前0-1的最小值为j,0-1的最大值为k,可知j的最大值为0,k的最小值为0;
            dp[0][0][0]表示空串
转移方程:dp[i+1][min(j+1,0)][k+1]+=dp[i][j][k];//第i+1位添0
                    dp[i+1][j-1][max(k-1,0)]+=dp[i][j][k];//第i+1位添1
由于j可能为负数,故加一个偏移值5
#include<cstdio>
#include<cstring>
#define ll __int64
const int W=5;
int n,k;
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
ll dp[63][10][10];
int main(){
	int i,j,p;
	while(~scanf("%d%d",&n,&k)){
		memset(dp,0,sizeof(dp));
		dp[0][W][W]=1;
		for(i=0;i<n;i++){
			for(j=-k+W;j<=W;j++)for(p=W;p<=k+W;p++){
				dp[i+1][min(j+1,W)][p+1]+=dp[i][j][p];
				dp[i+1][j-1][max(p-1,W)]+=dp[i][j][p];
			}
		}
		ll ans=0;
		for(i=-k+W;i<=W;i++)for(j=W;j<=k+W;j++)ans+=dp[n][i][j];
		printf("%I64d\n",ans);
	}
	return 0;
}


el-table通过上下左右键移动光标 在Element Plus的el-table中包含el-input和el-select组件,要实现上下左右键控制光标位置,需要通过focus和blur跟踪判断当前是哪个el-input或el-select有焦点,当按键按下时,通过监听,计算下一个获取焦点元素的索引,通过focus方法将焦点切换至改元素。 阅读详情

相关推荐

STM32中RS485方向控制引脚应用详解

深入解析STM32如何通过GPIO控制RS485通讯的方向引脚,实现半双工通信的精准切换。重点讲解硬件连接与软件时序配合,确保rs485通讯稳定可靠,适用于工业控制等实际场景。

weixin_42451850的博客 400

HDU1545(01-K Code)

dp[i][j][k]=dp[i-1][j+1][k-1]+dp[i-1][j-1][k+1].

huantwofat 1314

keil+Jlink GD32调试记录

Jlink+keil,GD32调试记录,踩坑及解决,持续更新。

SUN_BW的博客 2956

hdu_1545 01-K Code

难度为4的dp。。。。丫的!AC不解释!!!  最后两维表示从最末端 [最多1比0多][最多0比1多]  #include using namespace std; __int64 dp[111][11][11]; // 从最末端 [最多1比0多][最多0比1多] __int64 N,K,temp; inline void init()

量子流逝 1959

DSPACE仿真平台的使用

DSPACE仿真平台的使用 文章目录DSPACE仿真平台的使用1.ModelDesk新建项目2.MotionDesk引入项目3.ControlDesk引入项目4.项目整合运行 我们使用DSPACE仿真平台软件来模拟小汽车的自动驾驶。 总共需要用到DSPACE大类下的三个软件:ModelDesk、ControlDesk、MotionDesk。 1.ModelDesk新建项目 在桌面上点击ModelDesk图标,打开DSPACE—ModelDesk 选择 File 标签,侧边栏选择 New,点击 New A

qq_42582489的博客 7528

DLMS—Cryptographic algorithms—(Green-Book)加密算法

密码学是数学的一个分支,基于数据的转换,并且可以用来提供多种安全服务:保密性、数据完整性、认证、授权和不可否认性。密码学依赖于两个基本组成部分:算法(或密码学方法)和密钥。算法是一个数学函数,而密钥是在转换过程中使用的参数。密码算法和密钥用于对数据应用密码保护(例如,加密数据或生成数字签名),以及移除或检查保护(例如,解密加密的数据或验证数字签名)。密码哈希函数:这类函数不需要密钥(尽管它们可以以使用密钥的模式使用)。哈希函数通常用作算法的一个组成部分,以提供安全服务。见9.2.3.2节。对称密钥算法。

一个bug是bug,多个bug能work 1710

01-K Code [HDU 1545]

http://acm.hdu.edu.cn/showproblem.php?pid=1545 View Code const int MM = 11111; #define debug puts("wrong") typedef __int64 int64; int N,M; int64 dp[63][11][11];//j min(0-1) k max(0-1) void...

weixin_30376163的博客 173

单细胞RNA测序数据分析与可视化:从基础原理到高级应用

单细胞RNA测序(scRNA-seq)技术通过解析单个细胞的基因表达谱,显著提升了我们对细胞异质性的理解。本文详细介绍了scRNA-seq数据分析的完整流程,包括数据预处理、质量控制、降维、聚类、差异表达分析、细胞类型注释、细胞周期分析、轨迹分析、RNA速率分析、基因集富集分析、细胞通讯分析、批次效应校正以及空间转录组学整合。文章还展示了scrna_toolkit包在简化分析流程和增强数据可视化方面的应用。通过这一工具,研究者可以更高效地处理单细胞数据,揭示复杂的生物学信息。未来,该工具将进一步整合多组学分

2301_80338712的博客 4132

XLNet与ELECTRA在IMDb情感分析中的工程选型与实战微调

Transformer模型在文本情感分析中,核心挑战在于建模否定、转折与反讽等细粒度语义结构。BERT虽广泛应用,但其掩码语言建模(MLM)的独立性假设限制了对‘虽然…但是’类长程依赖的捕捉能力;而XLNet通过排列语言建模(PLM)显式学习词序条件概率,ELECTRA则以替换检测任务(RTD)强化上下文一致性判别——二者分别从结构建模与表征判别维度提升语义敏感度。这种架构差异直接转化为IMDb等真实影评数据上的精度跃迁与鲁棒性增强,尤其适用于含转折连词、长句及隐性情感表达的工业级场景。本文聚焦于这两类先进

weixin_34401479的博客 649

CCAR-23《正常类飞机适航规定》和CCAR-25《运输类飞机适航规定》差异分析

通过详细比较CCAR-23和CCAR-25在适用范围、设计标准、性能要求、运行限制、安全冗余和环境适应性方面的差异,我们可以看出,CCAR-23适用于轻型飞机,开发和运营成本较低,设计要求相对简单。而CCAR-25适用于大规模运输飞机,设计、开发、测试和运营管理都需要更高的复杂性和投入。

qq_41854911的博客 3706

【RT-DETR实战】112、NCNN模型转换与层实现支持:从模型文件到推理引擎的硬核实战

本文详细记录了将RT-DETR模型部署到NCNN框架的全过程及关键要点。作者首先遇到MultiHeadAttention等算子不支持的问题,通过ONNX中间转换和自定义层实现解决。文章具体介绍了PyTorch到NCNN的权重转换技巧、模型优化方法(包括量化和线程优化)以及调试经验,强调逐层对比输出、预处理检查和边界情况测试的重要性。最后分享了保持转换流程可复现性的实用建议,指出手动调试虽然耗时但能加深对模型的理解,体现了工程师在解决技术难题时的专业精神与成就感。

企鹅码农的专属播客,分享10多年的实战案例和经验解读,包含YOLO、RT-DETR、AI等各个工作领域。 43

HDU 1545(01-K Code)

动态规划题,设 dp[i][j][k] 表示长为 i 的子序列中,0 比 1 最多多 j 个,1 比 0 最多多 k 个。 如果第 i+1 位填0,则 dp[i + 1][j + 1][max(k - 1, 0)] += dp[i][j][k]; 如果第 i+1 位填1,则 dp[i + 1][max(j - 1, 0)][k + 1] += dp[i][j][k]。 #include <iostream> #include <cstring> #include <al

Intelligence1028的博客 388

用 deepseek 写小说(通用版提示词模板)

#Initialization:作为[Role],在[Goals]下,回顾你的[Skill],严格遵守[Constraints],5.第五步:人物大纲,给小说里的每个人物撰写背景故事,深挖人物过去的经历,原生家庭,住所:一栋位于市郊的房子,有三个卧室,房龄 10 年,厨房很大,当中有一个鸟式大理石。示例 2.戈德里洛克先去了熊老爹的工作坊,尝试用大纲法写作,却发现这种方法无聊透顶,1.第一步:一句话概括,一句话概述小说内容,主要包含小说癸型,主角,以及故事中需要。大灰狼的暴行彻底激怒了戈德里洛克,

陈奕昆的博客 2969

zoj 2745 01-K Code

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1745 题目大意: 对于一个01串,如果任意连续子串的0的个数和1的个数之差的绝对值不超过k(2~5),那么这个01串合法。 问有多少个长度为n(1~62)的合法串。 题目思路: 如果知道某长度为i合法串的后缀里最大的0和1的差,以及最大的1和

Go.To.AC的专栏 1146

深度学习工具包 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")

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Second——Training

#include #include #include #include #include using namespace std; #define M 12 char graph[M][M][M]; bool vis[M][M][M]; int n; struct Point{   int x,y,z;   int step;   bool operat

程序员的冷浪漫 887

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

DP ZOJ 2745 01-K Code

题目传送门 题意:要求任意连续子序列中0和1的数量差不超过k的方案数 分析:想好状态其实不难。dp[i][j][k]表示考虑前i长度,后缀中最大的 sum(0) - sum(1) = j, sum (1) - sum (0) = k的方案数,合并以下可以得到最大的|sum(0) - sum(1)| = j + k,所以j+k <= K,最后考虑当前i放0或1就可以转移状态了。 ...

weixin_33852020的博客 151

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

HDU1548:A strange lift(BFS)

HDU1548:A strange lift(BFS) Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 49   Accepted Submission(s) : 22 Font: Times New Roman | Verdana |

Kaidge的博客 350

九度OJ1545题目详解

九度OJ1545 题目,用到并查集的知识,顺便学习一下~

slam、机器人专家 513

01-K Code ZOJ

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2745 终于AC了,纠结了一天的一道题。。。。 题意: 给一个长度为N的string , 需要往里面填充一些0、1,约束条件就是N的任意一个substring的中0的个数和1的个数之差不能超过K。 算法: DP 分析: 一开始没有看到substring 。 以为就是要

Chris_Home 1121

hdu1545 dp[i][x][y]表示到i位,从i到之前1比0最多多x个,0比1最多多y个(注意边界)...

T^T老是把转移方程方向想错 1 #include<stdio.h> 2 #include<string.h> 3 long long dp[75][15][15]; 4 int main() 5 { 6 int n,k,i,j,x,y; 7 long long sum; 8 while (~scanf("%d...

weixin_34221036的博客 169

HDU1969:Pie(二分)

Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to

ACM!荣耀之路! 7466

HDU 1083 (匈牙利算法)

Problem Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactl...

Xiaofugongzi的博客 347

java开发常见问题总结

Java编程中的一些常见问题汇总 ..本文列举了我在周围同事的Java代码中看到的一些比较典型的错误。显然,静态代码分析(我们团队用的是qulice)不可能发现所有的问题,这也是为什么我要在这里列出它们的原因。 如果你觉得少了什么,请不吝赐教,我会很乐意把它们加上。 下面列出的所有这些错误基本都与面向对象编程有关,尤其是Java的OOP。 类名 读

bcbobo21cn的专栏 3万+

操作系统导论期末复习题

操作系统导论期末复习题进程进程调度策略和内存虚拟化机制memory virtualization并发Persistance持久化 进程 1、When a process makes a system call to transmit a TCP packet over the network, which of the following steps do NOT occur always? A、The process moves to kernel mode. B、The program counter

star_of_science的博客 5097

今天编程最后一道01k_code.cpp

//============================================================================ // Name        : 01k_code.cpp // Author      : mtt // Version     : // Copyright   : Your copyright notice // Descri

MTT_SKY 438

perf命令使用

perf Examples

zgl07的专栏 1万+
上一篇: UVA 1162 Transcript
下一篇: zoj 2838 Utopia
libing923
博客等级 码龄15年 12粉丝 71原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值