hdu5730 Shell Necklace

hdu5730(FFT+多项式求逆) (最近在班上好无聊,总感觉同学都好拽,也没有能说很多话的小姐姐,而且都很爱学习。老师也很死板,诸多要求。但我还是我,毕竟看过那么多治愈番。) 终有一天会降临,只属于我的苍蓝天使! 稳定的题面传送门 题意是这样的,长度分别为1..n的棒子各有a[i]种,每种都有无限条,问组成长度为n的大棒子有多少种方案,mod313。 设f[i]表示长度为i的方案数,根据题意f[0]=1,考虑dp。 枚举 阅读详情

题目:一段长为i的项链有a[i]种表达爱意的装饰方法,问长度为n的项链有多少种用上述方式组成的方法。

思路:dp[i]=∑dp[j]*a[i-j],(1<=j<=i-1)

要用fft+CDQ分治

代码:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<numeric>
using namespace std;
//#define PI acos(-1.0)
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define mm(a,b) memset(a,b,sizeof(a))
#define PP puts("*********************");
template<class T> T f_abs(T a){ return a > 0 ? a : -a; }
template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
// 0x3f3f3f3f3f3f3f3f
// 0x3f3f3f3f

const int maxn=200050;
const int mod=313;
const double PI=acos(-1.0);
struct Complex{//复数结构体
    double x,y;
    Complex(double _x=0.0,double _y=0.0){
        x=_x;
        y=_y;
    }
    Complex operator-(const Complex &b)const{
        return Complex(x-b.x,y-b.y);
    }
    Complex operator+(const Complex &b)const{
        return Complex(x+b.x,y+b.y);
    }
    Complex operator*(const Complex &b)const{
        return Complex(x*b.x-y*b.y,x*b.y+y*b.x);
    }
};
/*
*进行FFT和IFFT前的反转变换.
*位置i和 (i二进制反转后位置)互换
*len必须是2的幂
*/
void change(Complex y[],int len){
    int i,j,k;
    for(i=1,j=len/2;i<len-1;i++){
        if(i<j) swap(y[i],y[j]);
        k=len/2;
        while(j>=k){
            j-=k;
            k/=2;
        }
        if(j<k) j+=k;
    }
}
/*
*做FFT
*len必须为2^k形式,
*on==1时是DFT,on==-1时是IDFT
*/
void fft(Complex y[],int len,int on){
    change(y,len);
    for(int h=2;h<=len;h<<=1){
        Complex wn(cos(-on*2*PI/h),sin(-on*2*PI/h));
        for(int j=0;j<len;j+=h){
            Complex w(1,0);
            for(int k=j;k<j+h/2;k++){
                Complex u=y[k];
                Complex t=w*y[k+h/2];
                y[k]=u+t;
                y[k+h/2]=u-t;
                w=w*wn;//旋转因子
            }
        }
    }
    if(on==-1)
        for(int i=0;i<len;i++)
            y[i].x/=len;
}
Complex x1[maxn],x2[maxn];
int arr[maxn];
int dp[maxn];
void cdq(int L,int R){
    if(L==R){
        dp[L]=(dp[L]+arr[L])%mod;
        return;
    }
    int mid=(L+R)>>1;
    cdq(L,mid);
    int len=1;
    while(len<(R-L+1)) len<<=1;
    for(int i=0;i<len;i++)
        x1[i]=x2[i]=Complex(0,0);
    for(int i=L;i<=mid;i++)
        x1[i-L]=Complex(dp[i],0);
    for(int i=0;i<R-L+1;i++)
        x2[i]=Complex(arr[i+1],0);
    fft(x1,len,1);
    fft(x2,len,1);
    for(int i=0;i<len;i++)
        x1[i]=x1[i]*x2[i];
    fft(x1,len,-1);
    for(int i=mid+1;i<=R;i++){
        dp[i]+=(int)(x1[i-L-1].x+0.5);
        dp[i]%=mod;
    }
    cdq(mid+1,R);
}
int main(){

//    freopen("D:\\input.txt","r",stdin);
//    freopen("D:\\output.txt","w",stdout);
    int n;
    while(~scanf("%d",&n)){
        if(!n)
            break;
        for(int i=1;i<=n;i++){
            scanf("%d",&arr[i]);
            arr[i]%=mod;
            dp[i]=0;
        }
        cdq(1,n);
        printf("%d\n",dp[n]);
    }
    return 0;
}


Windows版本Carla(含RoadRunner插件)源码安装+RoadRunner地图导入 通过跳转浏览器账号密码登录github,不要选择Fine-grained personal access tokens,在git clone时会显示非授权,也不要使用Windows凭据!核心指令:编译PythonAPI–make PythonAPI,,编译Server–make launch,封装”游戏“–make package。完成安装后,在已安装->2022版本右侧->更多->导入配置,选择配置文件(需将配置文件内容更新为手册内容,如下图)->详细信息,更新。不要修改版本,执行上面指令即可! 阅读详情

相关推荐

汇率波动率建模实战:从GARCH到EGARCH的金融时间序列分析

在金融时间序列分析中,波动率建模是量化市场风险的核心技术。其基本原理在于捕捉金融资产收益率序列中存在的波动聚集、尖峰厚尾等典型特征。通过建立条件异方差模型,如GARCH及其扩展模型,可以动态估计和预测未来波动率,这对于资产定价、风险管理和投资决策具有重要价值。在金融工程领域,该技术广泛应用于外汇、股票和衍生品市场。本文以汇率波动率建模为具体场景,详细阐述了如何使用Python中的arch库,从数据预处理、模型选型(包括GARCH、EGARCH等)、参数估计到样本外预测评估的全流程实践,并深入探讨了模型在应对

weixin_32629853的博客 371

【HDU5730】Shell Necklace(多项式运算,分治FFT)

【HDU5730】Shell Necklace(多项式运算,分治FFT) 题面 Vjudge 翻译: 有一个长度为\(n\)的序列 已知给连续的长度为\(i\)的序列装饰的方案数为\(a[i]\) 求将\(n\)个位置全部装饰的总方案数。 答案\(mod\ 313\) 题解 很明显,是要求: \(f[n]=\sum_{i=0}^na[i]\times f[n-i],f[0]=0\) 卷积的形式啊。...

weixin_30799995的博客 146

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

本文将带你从0到1完整搭建一套基于LangChain和AutoGen的多智能体AI投研系统首先,我们会一起梳理智能投研的核心痛点、金融数据的独特性,以及为什么传统AI Agent,尤其是多智能体协同架构,是破局的唯一最优解;RAG检索增强生成(但这次是金融领域定制化的,包括向量检索+时序数据检索+知识图谱检索的“三元检索增强”)、AutoGen多智能体协同框架。

软件工程实践的博客 380

【HDU5730】 Shell Necklace

HDU5730 Shell Necklace 题目大意 已知连续i(1<=i<=n)个贝壳组合成一段项链的方案数a[i],求组合成包含n个贝壳的项链的总方案数。 Solution cdq分治 我们考虑最朴素的$dp​$. 设$f_i​$表示包含$i​$个贝壳的方案数,很容易写出转移方程: \(f_i=\sum_{j=1}^if_{i-j}×a_j\) 发现这个dp方...

araw94333的博客 278

Ubuntu 解决WPS缺少宋体,微软雅黑等中文字体

这篇博客解决Ubuntu 18.04 无法使用中文字体的问题 问题描述

分享日常的学习,开展的项目,编写的软件,解决的问题等~ 1万+

科研绘图系列:R语言circos图(circos plot)

科研绘图系列:R语言circos图(circos plot)

专注生信领域 3430

HDU 5730 FFT + 分治

题目链接 题意: 给定一个数组aaa,定义a[i]a[i]a[i]表示连续iii个珍珠可以装饰的方案数,求n个珍珠的项链可以装饰的方案总数。 思路: 定义: F[i]F[i]F[i]:iii个珍珠的项链可以装饰的方案总数 则很明显是一个动态规划,得: F[0]=1F[0] = 1F[0]=1 F[i]=∑j=1ia[j]∗F[i−j]F[i] = \sum_{j=1}^i a[j]*F[i-j...

新熊君的博客 463

*手把手教你学 Simulink——压缩机用永磁同步电机无位置传感器 I‑F 启动(Sensorless I/F Starting)控制仿真

dtdi^α​​zα​e^α​ω^θ^​=Ls​1​(−Rs​i^α​+usα​−zα​)=K⋅sign(i^α​−iα​)=zα​+Kpll​⋅(i^α​−iα​)同理 β=PLL(e^α​,e^β​)=∫ω^dt​。给定 Id​=Iset​, Iq​=f(θopen​)按设定 fstart​(t)Iq​=k⋅sin(θopen​)投影 → 恒幅 Is​=Id2​+Iq2​​。​ 将 Id​,Iq​→ Iα​,Iβ​→ SVPWM。Id​=Ialign​(弱对齐 → 防抖动)

amy_mhd的博客 38

HDU 5730 Shell Necklace

HDU 5730 Shell Necklace原题连接: http://acm.hdu.edu.cn/showproblem.php?pid=5730闻题而来。设组合成长度为kk的方案数量为:bkb_k方便起见。设b0=1,a0=0b_0=1,a_0=0对于长度为nn,项链最后一段长度为kk的方案数量为:bn−kakb_{n-k}a_k题目中没有指定的aa都可以用00代替下面给出的数列如果不足偶数

ZLH_HHHH的博客 579

RK3568下GPIO模拟串口

在嵌入式开发中,硬件 UART 资源可能被其他外设占用。此时,通过 GPIO 模拟 UART(软串口)成为一种灵活的解决方案。本文基于 RK3568 平台,结合 Linux 内核模块,实现高精度软串口通信,并深入分析关键技术细节。可以看到已经接收到数据了,可以自己创建自定义的设备文件到/dev下,也可以按照串口设备的标准创建一个设备,后面有时间我写一篇和标准串口设备结合的gpio模拟串口文章。RK3568 GPIO 模拟串口(软串口)实现详解。将编译好的驱动放到板子上运行。再写个Makefile。

文石_2009的博客 363

第44节:cesium 大雾效果(cesium自带)(含源码+视频)

cesium 大雾效果(cesium自带)

qq_29384639的博客 1702

hdu5730Shell Necklace

链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5730 题意:给定a数组,f[i]=sigma(f[i-j]*a[j]),j 分析:分治FFT,这题是学snowy_smile的,他分析的很详细,我就不再重复一遍了。 代码: #include #include #include #include #include #include #i

Fsss 854

华为MetaERP PTP采购到应付全流程解析

摘要:本文系统解析华为MetaERP中的PTP(采购到应付)全流程管理方案,涵盖从采购申请到付款执行的完整业务流程。文章详细分解了PR、PO、GR、IV、AP等关键环节的财务核算规则,并提供了预算校验、库存更新等Python代码示例。同时阐述了IT落地架构设计,包括会计引擎配置、系统集成方案及银企直连支付接口实现。该方案通过三单匹配自动化和智能会计引擎,将处理效率提升10倍(200笔/人天→2000笔/人天),实现98%的自动化率,为集团企业提供了高效的数字化财务管理样板。文中所有技术方案均需根据实际场景调

金牌架构师 1742

hdu 5730 Shell Necklace [分治fft | 多项式求逆]

hdu 5730 Shell Necklace 题意:求递推式\(f_n = \sum_{i=1}^n a_i f_{n-i}\),模313 多么优秀的模板题 可以用分治fft,也可以多项式求逆 分治fft 注意过程中把r-l+1当做次数界就可以了,因为其中一个向量是[l,mid],我们只需要[mid+1,r]的结果。 多项式求逆 变成了 \[ A(x) = \frac{f_0}{1-B(x)}...

weixin_30559481的博客 82

pscad IEEE标准系统搭建说明

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

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

HDU5730 Shell Necklace

本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! 题目链接:HDU5730 正解:分治$FFT$ 解题报告:   分治$+FFT$模板题。   容易发现一个$O(n^2)$的$DP$方程,就是一个卷积的形式,在分治过程中,用左边更新右边,做一次$FFT$。  ...

dgoh41514的博客 104

温度PID控制PLC程序

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

hdu 5730 Shell Necklace

分治+FFT

我要吃熊猫 395

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

hdu 5730 Shell Necklace —— 分治FFT

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5730 DP式:\( f[i] = \sum\limits_{j=1}^{i} f[i-j] * a[j] \) 因为没有给 \( f[0] \) 赋初值,所以在递归底层令 \( f[l] += a[l] \) 注意多组数据清空数组; 读入 \( s[i] \) 时要取模!! 代码如下:...

aodan5477的博客 142

【HDU 5730】Shell Necklace

http://acm.hdu.edu.cn/showproblem.php?pid=5730 分治FFT模板。 DP:\(f(i)=\sum\limits_{j=0}^{i-1}f(j)\times a(i-j)\) 递推第i位时要用到0到i-1位,cdq套FFT,考虑每一位上f的贡献即可。 时间复杂度\(O(n\log^2n)\)。 #include<cmath> #inc...

as2886089的博客 111

hdu5730 Shell Necklace

任意模数多项式求逆

ACoder 314
上一篇: ACdream - 1157 Segments
我不会额
博客等级 码龄11年 2粉丝 173原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值