UVA 12034-Race

【组合数学】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 阅读详情

Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

 Status

Description

Download as PDF

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 (  $ \le$1000), denoting the number of test cases. Each case starts with a line containing an integer  n (  1$ \le$n$ \le$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



Source

Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths ::  Examples
Root :: Prominent Problemsetters ::  Md. Mahbubul Hasan
Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Counting :: Exercises: Intermediate


小结:

    大概想法是递推,至于为什么是递推,因为题目分类就是递推(看到这里不要打我==),对于递归的想法,我感觉,对于每种情况的分类讨论是解决这类问题的关键。

就拿这道题目来说,在现有的名次中插入新个体是这种题目的常见思路。

令dp[i][j]=i个人组成的所有的名次的种类数目,那么对应的每个新插入的个体,对应2种情况:(1)增加现有的名次总数 (2)加入现有的任意一个名次中。

然后就会有以下递推方程:dp[i][j]=i==j?dp[i-1][j-1]*j:(dp[i-1][j]+dp[i-1][j-1])*j;

以下是AC代码:

//111,112,121,211,122,212,221,123,132,213,231,312,321
//当n的值为3的时候,排名的种数为13
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int mod=10056;
int dp[1005][1005];
void solve()
{
    int ans,n;
    int t;
    scanf("%d",&t);
    for(int m=1;m<=t;m++)
    {
        scanf("%d",&n);
        ans=0;
        for(int i=1;i<=n;i++)
        {
            ans+=dp[n][i];
            ans=ans%mod;
        }
        printf("Case %d: %d\n",m,ans);
    }
}
int main()
{
    int n;
    int mod=10056;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=1;i<=1000;i++)
    {
        for(int j=1;j<=i;j++)
        {
            dp[i][j]=i==j?dp[i-1][j-1]*j:(dp[i-1][j]+dp[i-1][j-1])*j;
            dp[i][j]=dp[i][j]%mod;
        }
    }
    solve();
    return 0;
}




利用NURBS曲线进行点云曲面拟合算法 点云拟合曲面算法是将点云数据拟合成一个二次或高次曲面模型的算法。这种算法主要用于三维模型重建、计算机视觉、机器人感知、医学图像处理等领域。最小二乘法(Least Squares Method):通过最小化点到曲面距离的平方和来拟合曲面模型。三角剖分算法(Triangulation-Based Method):将点云构建成三角网格,再拟合成曲面模型。隐式曲面算法(Implicit Surface Method):通过定义一个隐式函数来表示曲面,然后用点云数据来估计隐式函数的系数。 阅读详情

相关推荐

【Python机器学习实战】 | 基于PCA主成分分析技术读入空气质量监测数据进行数据预处理并计算空气质量综合评测结果

主成分分析(Principal Component Analysis, PCA)是一种常用的机器学习和数据分析技术,用于降低数据维度、识别数据中的模式、发现变量之间的关系等。

一伦明悦的博客 1263

(UVA - 12034)Race(组合数,dp)

链接: https://vjudge.net/problem/UVA-12034题意:A,B两个人赛马,最终名次有3种可能:并列第一;A第一,B第二;B第一A第二 现在n个人赛马,问最终名次的可能情况的个数对10056取模分析:设答案为f(n),假设第一名有i个人,有C(n,i)种可能性,接下来有f(n-i)种可能性,答案为所有的i(1<=i<=n) C(n,i)*f(n-i)f(0)=1 可以

feng_zhiyu的博客 851

【FPGA】定点数运算中的位宽优化与截取策略

本文深入探讨了FPGA定点数运算中的核心挑战——数据位宽优化与截取策略。针对定点数在加法、乘法等运算中位宽膨胀的问题,文章详细分析了位宽变化规律,并对比了直接截断、四舍五入和收敛舍入三大截取策略的优缺点及硬件实现方法。通过实战指南与避坑经验,旨在帮助开发者在保证计算精度的同时,高效利用FPGA资源,实现性能与面积的平衡。

weixin_29181861的博客 116

UVA12034Race

对问题进行适当的分解能够极大简化问题。本道题就时如此。 我们始终要记住:用已知求解未知!!

qq_16603365的博客 367

Aveva Marine C# 二次开发入门001

1# 引用 C:\AVEVA\Marine\OH12.1.SP4\Aveva.ApplicationFramework.dll C:\AVEVA\Marine\OH12.1.SP4\Aveva.ApplicationFramework.Presentation.dll 2# 引用命名空间, using Aveva.ApplicationFramework.Presentation;usi...

weixin_30245867的博客 1911

【IT小趣闻】免费的DeepSeek是如何赚钱的?

导语:目前很多的通用人工智能也就是所谓的AGI例如文心一言、豆包、通义千问和最近大火的DeepSeek都是免费给普通用户使用的,对开源商业模式不太熟悉的普通人可不太了解这免费背后的商业套路,下面我们就一起来揭秘。开源模式能降低用户信任成本、加速技术普及,而商业化服务则针对企业级需求。DeepSeek 可通过组合上述策略,在服务开发者社区的同时,满足企业客户的深度需求,实现可持续发展。你也看出来了,上边是DeepSeek生成的,讲的还是挺明白的。

SunMy的博客 1765

UVA - 12034 Race

Description Tamim and Lina, 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. B

那些年 1371

基于改进YOLO11的天际线检测算法:复杂光照与恶劣天气适配实战

针对特定任务的YOLO改进,不应追求通用SOTA,而应深入理解任务的物理退化机理。Retinex对应光照模型、FAD对应散射模型、Wise-IoU对应边界不确定性——每个改进都有明确的物理解释,而非盲目的模块堆叠。时序一致性:引入轻量级RNN/Transformer模块利用视频帧间信息补偿单帧退化;多模态融合:结合红外/NIR波段穿透雾霾,与可见光特征在FAD-Neck中交叉注意力融合;自监督预训练:在海量无标注天际线视频上用MAE预训练Backbone,缓解恶劣天气标注稀缺问题。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 95

UVa 12034 Race

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

寂静山林 801

C++ Qt6 qml CMakeLists.txt如何添加qrc文件

本文介绍了在Qt6项目中如何通过CMake管理QML图片资源。相比Qt5的qmake,CMake需要手动创建qrc文件并配置CMakeLists.txt。关键步骤包括:1)创建resources.qrc文件并添加图片资源;2)在CMakeLists.txt中设置CMAKE_AUTORCC为ON开启自动资源处理;3)使用qt_add_resources将qrc文件绑定到项目。配置完成后,可通过"qrc:alias"方式引用资源图片,解决了相对路径管理复杂的问题。

琅嬛福地 1453

【Zephyr存储专题】06_存储块设备驱动开发(Nand Flash)

本文介绍了基于Zephyr系统的NAND Flash驱动实现方案,重点阐述了Flash驱动模型的核心架构和关键API设计。

zero的博客 1802

Uva12034 Race 组合+递推

Uva12034 Race Description 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 ...

pxlsdz的博客 422

数据挖掘实战-基于情感分析+网络语义分析+LDA主题分析对大唐不夜城用户评论进行文本分析

本研究基于去哪儿网和携程网的1888条大唐不夜城游客评论数据,运用Python进行文本分析。通过情感分析发现游客评价以积极为主(占比约70%),中性占20%,消极占10%。采用ROSTCM6软件进行社会网络语义分析,识别不同情绪下的高频词汇。使用LDA主题模型将评论划分为3个主题(夜景、表演、美食),并分析主题强度随时间变化趋势。实验包含数据采集、预处理、情感分析、语义网络分析和LDA建模等完整流程,为景区管理优化提供数据支持。源代码涵盖爬虫、数据处理和可视化分析的全套实现。

m0_64336780的博客 1万+

UVa 12034 - Race

这算是排列组合吧,然后递推…… 很适合打表啊……

_____ 1419

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

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

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

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

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

UVA12034 Race【排列】

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 ...

海岛Blog 758

UVA.12034 Race (递推)

UVA.12034 Race (递推)## 题意分析现在有nn个人比赛,可以有并列,求解有多少种排名方案。 如当n=3n = 3 的时候,可以有111,112,121,211,123,132,213,312,321,231,122,212,221 共13种方案。考虑这样一件事情,首先要确定一下出来有多少个并列第一名,有ii种方案每种方案有Cin,i∈[1,n]C^i_n, i∈[1,n] 种情况。

Pengwill's Blog 334

题解:UVA12034 比赛名次 Race

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

Qiuliyang_csdn的博客 292

UVA12034 - Race

原题链接: https://vjudge.net/problem/UVA-12034 题解: dp方程:设dp[i][j]中,i为马匹的数量,j为马匹的名次(或者说团数,并列名次为一团)。 dp[i][j]=dp[i-1][j-1]*j+dp[i-1][j]*j; 方程解释:假设此时是两匹马在跑,那么有两种情况:1.两匹马有两个名次,2.两匹马并列一个名次; 那么如果多加一匹马,也有两种...

一条菜狗的博客 305

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

UVa12034 Race

原题链接:UVa12034 解析:排列组合公式:C(n,k) = C(n-1,k-1) + C(n-1,k)。 代码实例: #include&lt;cstdio&gt; const int maxn = 1000; const int MOD = 10056; int C[maxn+1][maxn+1], f[maxn+1]; // 递推出所有组合数 void init() { f...

帅比王的博客 491

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

uva12034 Race

递推+组合数递推

YHaX的博客 462

uva 12034 Race

uva 12034 Race

@fei 736
上一篇: POJ 3254-Corn Fields
下一篇: POJ 1185-炮兵阵地
Yuric
博客等级 码龄12年 0粉丝 49原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值