hdu 1028 Sample Ignatius and the Princess III (母函数)

Ignatius and the Princess III

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


Problem Description
"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.

"The second problem is, given an positive integer N, we define an equation like this:
  N=a[1]+a[2]+a[3]+...+a[m];
  a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
  4 = 4;
  4 = 3 + 1;
  4 = 2 + 2;
  4 = 2 + 1 + 1;
  4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
 

 

Input
The input contains several test cases. Each test case contains a positive integer N(1<=N<=120) which is mentioned above. The input is terminated by the end of file.
 

 

Output
For each test case, you have to output a line contains an integer P which indicate the different equations you have found.

 

Sample Input
4
10
20
 
Sample Output
5
42
627

 

C/C++:

 1 #include <map>
 2 #include <queue>
 3 #include <cmath>
 4 #include <vector>
 5 #include <string>
 6 #include <cstdio>
 7 #include <cstring>
 8 #include <climits>
 9 #include <iostream>
10 #include <algorithm>
11 #define INF 0x3f3f3f3f
12 #define LL long long
13 using namespace std;
14 const int MAX = 2e2 + 10;
15 
16 int n, ans[MAX], temp[MAX];
17 
18 void calc()
19 {
20     for (int i = 0; i <= 130; ++ i)
21         ans[i] = 1, temp[i] = 0;
22     for (int i = 2; i <= 130; ++ i)
23     {
24         for (int j = 0; j <= 130; ++ j)
25             for (int k = 0; j + k <= 130; k += i)
26                 temp[j + k] += ans[j];
27         for (int j = 0; j <= 130; ++ j)
28             ans[j] = temp[j], temp[j] = 0;
29     }
30 }
31 
32 int main()
33 {
34     calc();
35     while (~scanf("%d", &n))
36         printf("%d\n", ans[n]);
37     return 0;
38 }

 

转载于:https://www.cnblogs.com/GetcharZp/p/9557626.html

CADENCE 25.1打开元件库ERRORCannot perform the operation because of an exception. 摘要:解决CADENCE25.1打开元件库报错"ERRORCannotperformtheoperationbecauseofanexception"的方法:该错误通常由软件中文设置导致。解决方案为:进入Options→Preferences→MorePreferences,取消勾选两个本地语言选项后重启软件即可恢复正常。此方法简单有效,能快速解决因语言设置导致的元件库访问异常问题。(98字) 阅读详情

相关推荐

从零搭建VGGNet

在 forward 方法中实现了前向传播过程,包括卷积、激活、池化和平铺操作,最后通过全连接层得到分类结果。使用 torch.onnx.export 将模型导出为 ONNX 格式的文件 vgg.onnx。导出 ONNX:将模型导出为 ONNX 格式,便于在其他平台或框架中使用。定义 VGG 网络:构建了一个包含多个卷积层、池化层和全连接层的网络。使用 torch.save 将整个模型保存为 vgg.pth 文件。前向传播:对输入数据进行前向传播,得到输出结果。保存模型:将模型保存为 .pth 文件。

开源驱动,创造价值;坦诚清晰,快速失败;让复杂可计算。 521

HDU1026——Ignatius and the Princess I,HDU1027——Ignatius and the Princess II,HDU1028——Ignatius and the

a矩阵:存储迷宫的信息,其中X表示障碍物,表示空地,数字1-9表示需要战斗的格子。flag矩阵:标记格子是否已被访问过。d数组:定义了四个移动方向。node结构体:包含坐标y和x,以及到达该格子的步数step。pre数组:用于记录每个格子的前一个格子,以便回溯路径。

u014114223的博客 2101

手把手教你搭建基于Springboot+Vue的酒店管理系统

友友们,又是好久没更新了,马上元旦了,要迈入2025蛇年了,提前祝大家蛇年快乐,学有所成,本文博主将带领大家使用Springboot和Vue搭建一个酒店管理系统,受限于本文篇幅内容,本文罗列仅有部分简单示例内容,主要包括前后端示例源码。通过本文,你将大致掌握如何快速搭建一个现代化的Web应用。如果您想学习完整开发方案,包括项目源码+数据库文件+全套环境资源+代码部署视频教程+开发文档】获取学习资源,支持远程安装调试:一、项目背景随着互联网技术的不断发展,酒店行业对信息化的需求越来越高。

暴力码农的博客 1324

HDU1028 Ignatius and the Princess III

《ACM程序设计》期末上机考试安排 Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16565    Accepted Submission(s): 11675

MyHeaven7的博客 9759

从零到一:YOLOv11高帧率模型在RDK X5上的ONNX转换与部署实战

本文详细介绍了将最新的YOLOv11高帧率模型部署到地平线RDK X5开发板的完整实战流程。内容涵盖从PyTorch模型导出ONNX、地平线工具链环境配置与模型量化编译,到编写高效的板端推理代码,并针对高帧率目标进行了后处理优化。通过实战避坑指南,帮助开发者在RDK X5上实现30FPS以上的实时目标检测。

weixin_29089057的博客 139

Unity机械拆装实战:5步搞定发动机模型交互式装配(附完整代码)

本文详细介绍了在Unity中实现高交互性机械拆装仿真的完整流程。以发动机模型为例,通过5个核心步骤:项目初始化与模型准备、核心交互实现、智能装配逻辑、场景管理与相机控制、进阶优化与扩展,系统讲解了从零构建交互式装配功能的方法,并提供了完整的代码示例。

weixin_28049429的博客 215

hdu 1028 Ignatius and the Princess III(母函数,完全背包)

http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分问题。 第一道母函数。。。 小于等于n的整数共有n个,1,2......n,每个数都有无限多个,对于整数1,它所对应的母函数为(1+x+x^2+...+x^k+...),整数2对应的母函数为(1+x^2+X^4+...+x^(2*k)+...),整数3对应的母函数为(1+x^

1485

无法联网的情况下,dbeaver离线安装数据库驱动-clickhouse

无法联网的情况下,dbeaver离线安装数据库驱动-clickhouse

u012831187的博客 1万+

[母函数]HDU 1028 Ignatius and the Princess III

传送门:Ignatius and the Princess III Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11066    Accepted Submis

jjaw2013 742

控制障碍函数(Control Barrier Function,CBF) 二、示例

使用一个经典简单的示例讲解CBF的推导

Lyajpunov的博客 6433

Nifi SNI 问题解决方案

Nifi 在配置 SSL 时,如果没有正确设置主机名(SNI),就会导致。为了解决这个问题,我们需要重新配置 Nifi 的 SSL 证书,并确保所有相关配置项(如服务器地址、证书路径和密码等)正确无误。以下是一个详细的解决步骤,以帮助你正确配置 Nifi 并解决 SNI 错误。文件中的配置项(如服务器地址、端口和证书路径),以及正确设置用户凭证。通过这些配置,你可以确保 Nifi 在支持 HTTPS 的同时,正确处理 SSL/TLS 的 SNI 问题。文件,配置服务器地址、端口以及证书路径和密码。

m0_58786911的博客 2296

HDU1028Ignatius and the Princess III母函数入门

这个题也可以用递归加记忆化搜索来A,不过由于这题比较简单,所以用来做母函数的入门题比较合适 以展开后的x4为例,其系数为4,即4拆分成1、2、3之和的拆分数为4; 即 :4=1+1+1+1=1+1+2=1+3=2+2 这里再引出两个概念整数拆分和拆分数: #include #include #include #include #include #inclu

GXwar の Code library 1073

Colmap中 patchmatch源码

惊世骇俗的Colmap PatchMatch源码 500多行,简明易懂 先了解PatchMatch的options: max_image_size: 任一维度的最大图像尺寸 gpu_index: gpu的下标 depth_min,depth_max: 随机采样的深度范围 window_radius:用于计算NCC(两图片的归一化互相关),NCC的计算需要用到 win_size. 图像匹配 | NCC 归一化互相关损失 | 代码 + 讲解 - 知乎 (zhihu.com) window_step: 用.

qq_24884193的博客 2210

HDU 1028 Ignatius and the Princess III(母函数)

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15794Accepted Submission(s): 11138 Description "Well, ...

b502540662的博客 211

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

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

hdu1028-Ignatius and the Princess III (母函数模板)

由于校选题考察母函数,我能力有限,所以x

ITCTO-疯男的优快云博客 550

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

HDU 1028 Ignatius and the Princess III (母函数 , DP)

Ignatius and the Princess IIITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22045 Accepted Submission(s): 15395Problem Description “Well,

南风古 309

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

【母函数】hdu1028(Ignatius and the Princess III)

多项式乘法:(1+a1x)(1+a2x)……(1+anx)=1+(a1+a2+......+an)x+(a1a2+a1a3+......an-1an)x2+.......+a1a2a3...anxn可以看出x2项的系数a1a2+a1a3+...+an-1an中所有项包括n个元素,a1,a2.....an中的两个组合的全体,同理以此类推。 母函数定义:对于序列a0,a1,a2.....构造一函数:

寻找、发现、追求、获得———这就是狼的生活要素 724

HDU:1028 Ignatius and the Princess III

母函数

温姑娘的博客 273

HDOJ 1028 Ignatius and the Princess III

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题目: Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 122

u010084308的专栏 1476

HDU1028 Ignatius and the Princess III 生成函数

HDU1028 Ignatius and the Princess III 题意: 给一个整数n,将其拆成整数的和,问有多少种拆分方法。 解题思路: 每次将两个()里面的合并为一个,并只保存指数小于等于 n 的项 。 AC代码: #include&lt;iostream&gt; #include&lt;cstdio&gt; using namespace st...

Hagtaril 300

hdu1028 Ignatius and the Princess III

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1028 递归能跑。。。 但是我交了直接超时了,然后我就把数据跑出来了再交的,等的时间有点长(怪不得超时)。 过的有点猥琐,看别人代码用母函数过的。 1 #include 2 #includestring.h> 3 #include 4 #include 5 #include

xuesen1995的专栏 150

HDU 1028 Ignatius and the Princess III

HDU

loser 289

Ignatius and the Princess III (HDU-1028)(母函数)

"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says. "The second problem is, given an positive integer N, we define an equation like this: N=...

菜鸡的博客 272

hdu 1028 Ignatius and the Princess III 【整数划分】

Ignatius and the Princess III                                                                                       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other

Fighting! 1643

【母函数初学】Ignatius and the Princess III hdoj 1028

Ignatius and the Princess III hdoj 1028 (母函数初学)题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题目大意: 求一个整数能拆分的方法总数。 题目思路: 反向的母函数麽,跟1085题的不同处,我来解析下。 1085题是给你 分解的“单位值”(1,3,5),和其个数,求其最小不能组成的数; 102

学无纸巾 551

HDU 1028 Ignatius and the Princess III(动态规划+递归+母函数)

动态规划+递归+母函数

King 519
上一篇: hdu 5495 LCS (置换群)
下一篇: hdu 2188 悼念512汶川大地震遇难同胞——选拔志愿者 (巴什博弈)
devon2014
博客等级 码龄12年 3粉丝 144原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值