UVA 12034 Race 动态规划+递推

汽车诊断工程师必看:UDS 0x22服务实战,手把手教你用CANoe读取DID数据(附完整报文分析) 本文深入解析UDS协议中的0x22服务(ReadDataByIdentifier),从CANoe环境搭建到DID数据读取的实战技巧,涵盖单DID请求、多DID组合及复合DID应用。通过真实案例和CAPL脚本示例,帮助汽车诊断工程师高效解决常见问题,提升ECU数据读取效率。 阅读详情
Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded
and wandered around, even in their holidays. They passed several months in this way. But everything
has an end. A holy person, Munsiji came into their life. Munsiji took them to derby (horse racing).
Munsiji enjoyed the race, but as usual Disky and Sooma did their as usual task instead of passing some
romantic moments. They were thinking- in how many ways a race can finish! Who knows, maybe this
is their romance!
In a race there are n horses. You have to output the number of ways the race can finish. Note that,
more than one horse may get the same position. For example, 2 horses can finish in 3 ways.
1. Both first
2. horse1 first and horse2 second
3. horse2 first and horse1 second
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases. Each case starts with a
line containing an integer n (1 ≤ n ≤ 1000).
Output
For each case, print the case number and the number of ways the race can finish. The result can be
very large, print the result modulo 10056.
Sample Input
3
1
2
3
Sample Output
Case 1: 1
Case 2: 3

Case 3: 13

dp[i][j]表示第i匹马分j次到达的方法数

递推公式为dp[i][j]=(dp[i][j-1]+dp[i-1][j-1])*j;

dp[i][j-1]为第i匹马与前面的马一起到达,dp[i-1][j-1]代表第i匹马单独到达,一共有j种情况

还有就是取模公式

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=10056;
int dp[1100][1100];
int ans[1100];
void Init()
{
    int i,j;
    memset(dp,0,sizeof(dp));
    memset(ans,0,sizeof(ans));
    dp[0][0]=1;
    int sum;
    for(i=1;i<=1000;i++)
    {
        sum=0;
        for(j=1;j<=i;j++)
        {
            dp[i][j]=((dp[i-1][j]+dp[i-1][j-1])%mod*j%mod)%mod;
            sum=(sum%mod+dp[i][j]%mod)%mod;
        }
        ans[i]=sum;
    }
}
int main()
{
    Init();
    int t;
    scanf("%d",&t);
    int count=0;
    while(t--)
    {
        count++;
        int n;
        scanf("%d",&n);
        printf("Case %d: %d\n",count,ans[n]);
    }
    return 0;
}


【组合数学】Race, UVa12034 #include using namespace std; int T,casecnt,n;typedef long long LL; const int mod = 10056; int dp[1001],c[1001][1001]; int main() { ios::sync_with_stdio(false); c[0][0]=1;dp[0]=dp[1]=1; for(int i=1 阅读详情

相关推荐

SSD盘符漂移导致OSD down场景模拟与恢复

运维团队反馈一个问题,现象是:某个OSD对应的cache分区发生了变化,比如原来cache使用的分区是/dev/sde,后来还是这块盘,但分区信息不知何故,变成了/dev/sdf(产品OSD设备并不是根据分区名称来map,而是根据partlabel),最终的现象是这个OSD down了,没法启动.接到这个现象的反馈后,记录一下这个问题在lab的复现方法。

Gavin Blog 942

uva1025 动态规划

这道题的边界是dp(T,N)=0,状态dp(i,j)表示在时间i、第j个车站最少等待时间,有三个决策:1、等1分钟 2、如果有向左的车,向左 3、若果有向右的车,向右 转移方程就是dp(i,j)=min(dp(i+1,j),dp(i+t[j],j+1),dp(i+t[j-1],j-1)) AC代码: #include<cstdio> #include<cstring>...

weixin_30736301的博客 181

STM32F4与LAN8720硬件连接避坑指南:从原理图到RMII信号完整性的实战解析

本文深入解析了STM32F4与LAN8720以太网连接的硬件设计要点与常见陷阱。重点剖析了电源上电时序、复位电路设计、RMII接口配置等关键环节,并提供了从原理图设计到PCB布局、信号完整性调试的完整实战指南,帮助硬件工程师规避设计风险,确保以太网通信的长期稳定运行。

weixin_29189003的博客 212

uva10759(动态规划)

题意: 给出n和x,计算丢n个骰子,点数和大于等于x的概率,用分数表示; 思路: sum[i]表示投i个骰子一共有几种情况; num[i][j]表示投j个骰子,出现小于j的情况有几种; 那么我们可以知道 num[i][j]如果在多投一次; 如果投出1; 那么就可以得出num[i+1][j+1] += num[i][j];(因为所有num[i][j]的情况再投一次1,都会是n

潜水的程序猿 920

AI Agent在智能投研中的实战:多智能体信息整合与策略生成

那么,什么是AI Agent?简单来说,AI Agent是一种能够感知环境、做出决策并采取行动的自主系统。自主性:能够在没有人类直接干预的情况下运行,对自己的行为和内部状态有一定的控制权。反应性:能够感知环境的变化,并及时做出反应。主动性:不仅能够对环境变化做出反应,还能够主动地设定目标并采取行动实现这些目标。社会性:能够与其他Agent(包括人类和人工智能)进行交互、协作和竞争。它们可以全天候不间断地监控和处理海量信息,大大提升信息处理能力;

AI大模型应用之禅 191

Grok 3国内怎么用?超详细使用指南+实用指令模板

主要是用于快速分析学术论文,提取关键信息,总结研究成果。Analyze the following research paper: [粘贴或上传论文内容]1. Extract key findings, methodologies, and conclusions. (提取主要发现、方法和结论。2. Identify statistical significance and data points. (识别统计显著性和数据点。

Survivor_sl的博客 1万+

动态规划(装满水的气球,uva 10934)

一开始 rte 是因为用了%I64d而没用%lld。在VJ上做的忘了是UVA上的题 后来 tle 是因为用了 while(scanf("%lld %lld",&k,&n),k+n) 而没用 while(scanf("%lld %lld",&k,&n)&&k)。题目描述与样例输入不符。还记得刘汝佳的一句话:程序要尽量写的鲁棒,因为哪怕是世界级的比赛,都会因为题目描述错了或者疏忽从而导致无法AC。这

xl2015190026的博客 902

EDEM-FLUENT耦合报错几大原因总结(持续更新)

EDEM-FLUENT耦合报错几大原因总结(持续更新)

zheaa的博客 2761

uva 11584 动态规划

给定一串字符串,看最少能把它分成几个回文字符串。 SampleInput 3 racecar fastcar aaadbccb SampleOutput 1 7 3 dp[i]=min(dp[j]+1);(i~j为回文)。开始一看数据是1000,没敢写,去网上看了看都是这样做的,只好也跟着这样做,本以为是O(n^3)的复杂度,现在看来

liyunlonghere 491

2026.4.15:超详细自动安装Ubuntu-Server的保姆级教程

这篇教程详细介绍了如何创建无人值守的Ubuntu Server 26.04自动安装镜像。主要内容包括:从安装镜像中提取autoinstall-user-data文件并修改为user-data配置文件;使用mkpasswd生成加密密码;通过软碟通工具修改ISO镜像,添加自动安装所需的user-data和meta-data文件;编辑grub.cfg引导文件以启用自动安装模式。教程提供了完整的yaml配置示例,包含网络、存储、用户等设置,并演示了最终制作完成的自动安装镜像效果。

拥抱具身智能,昇腾Ascend C 748

171、运动控制中的标定:摩擦力与死区补偿标定

摘要(149字) 运动控制系统中的摩擦力与死区补偿是提升精度的关键。摩擦力分为静摩擦、库仑摩擦和粘滞摩擦,其中Stribeck效应是低速抖动的主因;死区则表现为控制信号的无效区间。有效标定方法包括恒速测试(摩擦力)和斜坡响应法(死区)。补偿策略需采用分段前馈和动态调整,避免过度补偿导致振荡。实践中要注意机械状态检查、补偿量限幅,并定期重新标定。硬件升级配合算法补偿才能实现最优控制,标定工作应优先于PID参数调整。

m0_50546716的博客 231

UVa 12034 Race

本题的关键在于将名次排列问题转化为有序划分问题,通过组合数学和动态规划的结合高效求解。预处理组合数和dpdpdp数组后,每个查询可以在O1O(1)O1时间内完成,适合nnn较大的情况。这种将问题分解为"第一名有几种情况,剩下的子问题递归解决"的思路,在很多计数问题中都有应用,值得掌握。

寂静山林 801

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

UVA 12034 - Race(递推)

UVA 12034 - Race 题目链接 题意:给定n匹马,要求出可能的排名情况(可能并列) 思路:递推,dp[i][j]表示i匹马的时候有j种不同名次,那么dp[i][j]可以由dp[i - 1][j - 1]插入j个不同位置得来,或者由dp[i - 1][j]放入已有j的名次得来,得到递推式dp[i][j] = j * (dp[i - 1][j - 1] + dp[i - 1]

Remilia's 1441

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

UVA 12034-Race

UVA 12034-Race

Yuric的专栏 672

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

题解:UVA12034 比赛名次 Race

求 n 个人赛马最终名次的可能性的个数。

Qiuliyang_csdn的博客 292

uva 12034 - Race(dp计数)

题目链接:uva 12034 - Race 题目大意:有n匹马比赛,问说有多少种排名情况,可以并列。 解题思路:dp[i][j]表示i匹马,最后一名为j的情况,转移方程dp[i][j]=(dp[i−1][j]+dp[i−1][j−1])∗j #include #include typedef long long ll; const int N = 1005; const ll

不慌不忙、不急不躁 1802

Race UVA - 12034

问题 分析 设i个人排列的名次可能性有f(i)种,现在一共是n个人,第一位是i(1<=i<=n)人并列,所以剩下的n-i重新排列,可能数f(n)=∑i=1nC(n,i)f(n−i),f(0)=1f(n)=\sum_{i=1}^nC(n,i)f(n-i),f(0)=1f(n)=∑i=1n​C(n,i)f(n−i),f(0)=1 #include <cstring> #incl...

zpf1998的博客 229

uva 12034 Race递推

点击打开链接 //f[i] i个人的排名方法数 //按第一名进行分类计数 f[i]=c(n,k)*f[n-k](k为第一名人数 k=1~n) #include #include #include using namespace std; const int N=1e3+20; const int mod=10056; typedef long long ll; ll f[N+2

Masamiiiiii 415

race(数论,组合,递推)

链接:https://vjudge.net/problem/UVA-12034 First:首先我们可以根据紫书上的思路来 设n个人的名次可能为f(n) 假设第一名有i个人,i个人是第一名的组合是C(n,i)后面的n-i个人就是f(n-i) 所以f(n)=C(n,1)f(n-1)+C(n,2)f(n-2)+…+C(n,n)f(0) 所以最后一项为前n个人并列第一名C(n,n)为1 要提前设置为f(0)为1 结果我发现这样子会爆long long 而且在计算组合数的时候 我利用了公式C(n,k+1)=(n-k

qq_51379351的博客 302

UVA 12034 Race

Race Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description   Race  Disky and Sooma, two of the bigg

码代码的猿猿 1243

UVA12034Race(DP)

题目链接 题意:A、B两人赛马,最终名次有三种可能:并列第一;A第一,B第二;B第一,A第二。输入n,求 n 人赛马时最终名次的可能,结果对10056取余 分析:对于 i 匹马来说,有 i 中可能,设dp[i][j]表示 i 匹马,j次到达的方案数,递推方程式 dp[i][j] = j * dp[i - 1][j] + j * dp[i -1][j - 1] 对于第i匹马来看有两种可...

apk6909的博客 437

【递推】Race UVA - 12034 【赛马】

【递推】Race UVA - 12034 【赛马】 Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded and wandered around, even in their holidays. They passed several months ...

Floraqiu的博客 431
上一篇: UVA 1635 Irrelevant Elements 唯一分解定律
下一篇: POJ 3259 Wormholes
哈哈哈哈666
博客等级 码龄10年 0粉丝 61原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值