HDU1028 Ignatius and the Princess III 生成函数

Magic+Arsenal+2.51 个人最喜欢的Unity特效包,仅供个人开发者使用,希望帮到大家! 立即下载

HDU1028 Ignatius and the Princess III


题意:

  • 给一个整数n,将其拆成整数的和,问有多少种拆分方法。

解题思路:

  • 生成函数
  • 每次将两个()里面的合并为一个,并只保存指数小于等于 n 的项 。

AC代码:

#include<iostream>
#include<cstdio>
using namespace std;
#define fread() freopen("in.txt","r",stdin)
#define sf scanf
#define pf printf
typedef long long ll;
const int N = 10001;

int n,c1[N], c2[N];
int main()
{
    while(~sf("%d",&n)){
        for(int i=0;i<=n;i++){
            c1[i] = 1;
            c2[i] = 0;
        }
        for(int i=2;i<=n;i++){
            for(int j=0;j<=n;j++){
                for(int k=0;j+k<=n;k+=i){
                    c2[j+k] += c1[j];
                }
            }
            for(int i=0;i<=n;i++){
                c1[i] = c2[i];
                c2[i] = 0;
            }
        }
        pf("%d\n",c1[n]);
    }

    return 0;
}
Arsenal III Arsenal III是一个综合的星际争霸修改工具。它可以直接修改星际争霸的Dat文件,并将它们保存成可制作MPQ的格式。 立即下载

相关推荐

TexGen模型导出到ABAQUS的inp文件:如何快速修改纱线材料属性(避坑指南)

本文针对TexGen模型导出到ABAQUS的inp文件后纱线材料属性缺失或错误的问题,提供了高效的解决方案。文章详细解析了inp文件结构,指导用户如何手动定位并修改纱线材料属性,并提供了可批量处理的Python脚本,帮助用户快速、精准地完成材料参数赋值,有效提升复合材料仿真工作效率。

ice55的博客 608

hdu 1028 & hdu 1398 —— 整数划分(生成函数)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分,每个数可以用无限次; 所以构造 f(x) = (1+x+x2+x3+...)(1+x2+x4+...)(1+x3+x6+...)...(1+xn) 乘起来后的 xn 的系数就是方案数; 用两个数组做即可,从第一个括号开始一个一个乘,f[i] 表示此时 xi 项的系数,后面...

aodan5477的博客 362

Unity 2022.3.3 LTS + Visual Studio 2022:手把手教你复刻《吸血鬼幸存者》核心战斗(附完整项目源码)

本文详细介绍了如何使用Unity 2022.3.3 LTS和Visual Studio 2022从零构建《吸血鬼幸存者》式战斗系统。通过图文开发教程,涵盖对象池优化、ECS架构雏形、2D物理碰撞控制等关键技术,帮助开发者高效复刻这款热门游戏的自动攻击与海量刷怪机制。

weixin_30721077的博客 466

[HDU-1028] 生成函数 入门题

拆分整数N,问有几种方案。 相当于有若干i,进行组合。 构造生成函数: 最后的系数就是结果。 用n^3的循环跑出结果。 g[i][j],表示处理到第 i&1 种数凑成 j 的方案数是多少? #include<iostream> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; const int M = 200+7; ll g[2][

bjfu170203101的博客 295

FreeRTOS OTA实战:从Bootloader设计到安全升级的完整流程(附MQTT示例代码)

本文详细介绍了在FreeRTOS系统中实现安全OTA固件升级的完整流程。内容涵盖从Bootloader设计、存储分区规划到与MQTT协议集成的OTA Agent任务开发,并重点解析了固件签名验证、防回滚等关键安全机制,为嵌入式物联网设备提供了一套高可靠性的远程升级解决方案。

weixin_29248653的博客 164

Chatbox使用指南

Chatbox使用指南

weixin_65289420的博客 2万+

hdu 1028

  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 生成函数是说,构造这么一个多项式函数g(x),使得x的n次方...

weixin_34061555的博客 205

在 SAP BTP 中通过 MTA 自动创建 Service Broker 的原理与实战

本文探讨了如何在SAP BTP的Cloud Foundry环境中通过MTA部署自动创建和注册Service Broker。传统手动注册方式存在依赖管理员、环境一致性差等问题。通过MTA部署可实现自动化Broker注册,利用占位符生成安全凭证,并确保平台端与应用端认证一致。文章详细解析了关键配置参数,包括create-service-broker标志、Broker名称、认证凭据和访问URL的设置方法。这种基础设施即代码(IaC)方式能提升DevOps实践水平,使服务注册成为应用部署流水线的有机组成部分。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 205

hdu1028 Ignatius and the Princess III 生成函数

题目链接:传送门 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 defin...

The_OIer的博客 317

基于MUSIC算法的DOA估计Matlab仿真

特别需要指出的是:通道与阵元并不是一一对应,通道是由空间的一个、几个或所有阵元合成的,当然空间某个特定的阵元可包含在不同的通道内。空间谱估计侧重于研究空间多传感器阵列所构成的处理系统对感兴趣的空间信号的多种参数进行准确估计的能力,其主要目的是估计信号的空域参数或信源位置,这也是雷达、通信、声纳等许多领域的重要任务之一。从系统框图中可以清晰的看出,估计空间相当于是对目标空间的一个重构过程,这个重构的精度由众多因素决定,如环境的复杂性、空间阵元的互耦、通道不一致、频带不一致等。

FPGA/MATLAB学习教程/源码/项目合作开发 1750

图神经网络实战——利用节点回归预测网络流量

在机器学习中,回归指的是对连续值的预测。通常与分类形成鲜明对比,分类的目标是找到正确的类别(即离散值,而非连续值)。在图数据中,分类和回归分别对应于节点分类和节点回归。在本节中,我们将尝试预测每个节点的连续值,而非分类变量。

盼小辉丶的博客 1万+

HDU1028 Ignatius and the Princess III(生成函数)

传送门 给定数字nnn,可以把它拆分为多少种a+b+c....a+b+c....a+b+c....的形式。 这是很经典的整数拆分问题 设数kkk的生成函数为 1+xk+x2k+x3k.......1+x^k+x^{2k}+x^{3k}.......1+xk+x2k+x3k....... 把[1,n][1,n][1,n]所有的生成函数乘起来,得到的xnx^nxn的系数就是答案了… 最朴素的暴力乘用时46ms46ms46ms #include <bits/stdc++.h> using names

jziwjxjd的博客 696

锂电池的充电和放电曲线解读

锂电池充放电曲线是反映其性能的关键指标。充电曲线分为恒流和恒压两阶段:恒流阶段电压快速上升,恒压阶段电流逐渐降低;放电曲线则呈现平台期和快速衰减期特征。这些曲线受温度、充放电倍率及材料体系(如三元锂或磷酸铁锂)显著影响。通过分析曲线特征,可优化电池管理系统,实现精准的SOC估算、快充策略制定及故障诊断,从而在电池性能与安全性间取得平衡。不同应用场景(如新能源汽车或消费电子)对曲线形态有特定要求。

start_up_go的博客 5093

HDU 1028 Ignatius and the Princess III(生成函数)

题目大意:让你把 n 拆成几个数字相加,有几种方案。4 = 3 + 1 和 4 = 1 + 3 是同一种方案 有一种 dp 的做法,首先我们让所用数字按升序来排,dp[i][j] 表示凑出 i,最大的那个是 j 的方案。 转移方程类似背包dp。 第二种做法是生成函数:转化题意,相当于让你求 1∗e1+2∗e2+3∗e3+...+n∗en=n1*e_1 + 2 * e_2 + 3 * e_3 +...

qq_41997978的博客 231

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

【HDU - 1028】Ignatius and the Princess III(生成函数)

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

__似水流年__的博客 286

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

HDU-1028 Ignatius and the Princess III(DP[完全背包]||生成函数)

解法一:DP[完全背包] 母函数入门题,但是看着这种母函数的模版就觉得像完全背包,实际一看题,第一反应还是完全背包 因为本题数的拆分不考虑顺序,所以只考虑方案的序列非减即可,用完全背包的方法从数1开始枚举到数n即可 解法二:生成函数

idealism_xxm的专栏 819

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数

HDU - 1028 step1:初始化第一个多项式 也就是 由1的各种方案 组 成 的多项式 初始化系数为 1。临时区 temp初始化 为 0 step 2:遍历后续的n - 1 个 多项式 ,第二重 for j 代 表 的 存 储 结 果 的 多 项 式的次数,k 代表 当前 第 i 的 多项式的次数 通过计算发现两个多项式相乘 其中一个 系数为1和 0 组成,运算时可以初始...

weixin_30855099的博客 80

hdu 1028 Ignatius and the Princess III 生成函数 模板题

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

liluoyu_1016的博客 263

母函数 生成函数 模板 HDU 1028 Ignatius and the Princess III

题意:给出一个N,问N的划分数 题解:显然n的划分数等于(1+x+x^2+...)*(1+x^2+x^4+...)*(1+x^3+x^6+...)的结果中x^n次前的系数 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 200; int n; int c1[...

Adolphrocs的博客 261

hdu 1028 Ignatius and the Princess III【生成函数】

老是想着化简,实际上O(n^3)就行了…… 写成生成函数是\( \prod_{i=1}^{n}(1+x^i+2^{2i}+...+x^{ \left \lfloor \frac{n}{i} \right \rfloor }) \),暴力乘即可 #include<iostream> #include<cstdio> using namespace std; const int...

weixin_30505751的博客 69

[省选前题目整理][HDU 1028]Ignatius and the Princess III(生成函数)

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1028题目大意给出一个数字nn,将它分解为若干个正整数之和,问有多少种方案? 比如,对于n=4n=4,有下列5种方案: 4 = 4; 4 = 3 + 1; 4 = 2 + 2; 4 = 2 + 1 + 1; 4 = 1 + 1 + 1 + 1; 思路很容易构造出

某沙茶的OI代码库 622

hdu 1028 Ignatius and the Princess III(生成函数)

初学母函数。。。 http://www.wutianqi.com/?p=596 看的这个博客对母函数的讲解,不过感觉他在模板的注释中③那里注释有点错误。j指代的应该是指数,自己写两个式子算算就能看出来。#include <cstdio>const int MAXN = 130; int C1[MAXN]; int C2[MAXN];int main() { int num; wh

梦幻的蔷薇色 327

HDU - 1028 Ignatius and the Princess III 生成函数+dp+完全背包

题目链接 题意: 基本整数划分问题 思路:    第一次接触生成函数问题,这个题目就是一个基础的生成函数问题.    我们构造生成函数为 (1+x+x^2+x^3....)(1+x^2+x^4+....).....(1+x^n)    用x来表示数,指数表示数的大小    解得x^n的系数即为所求. #include #define Ri(a) scanf("

Marcus-Bao的个人主页 1402

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

一道整数划分的题目,题目给出一个数,问这个数能有几种划分的方案,直接用生成函数(也就是母函数)就可以得到,题目中的数字到120,先提前把表打出来然后需要哪个输出哪个就行了,具体的不多说了= =直接放代码了 #include #include #include #include using namespace std; #define m 120 int a[130],b[130]; int i

富士山下 360
上一篇: HDU1796 How many integers can you find 容斥原理
下一篇: DHU3037 Saving Beans Lucas卢卡斯定理模板题
Hagtaril
博客等级 码龄9年 40粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值