$dp$,组合数。

$dp[i][j]$表示只用数字$i$,$i+1$,$i+2$......,$9$,凑成长度为$j$的并且数字$i$到$9$符合要求的方案数。只要枚举数字$i$用几个就可以转移了。

$dp[i][j] = \sum\limits_{k = a[i]}^n {(dp[i + 1][j - k]} *c[j][k])$,$0$的时候需要特别写一下转移方程,因为$0$不能放在第一位。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std; int n,a[],sum[];
long long c[][],dp[][];
long long mod=1e9+; int main()
{
for(int i=;i<=;i++) c[i][]=c[i][i]=;
for(int i=;i<=;i++)
{
for(int j=;j<i;j++)
{
c[i][j]=(c[i-][j-]+c[i-][j])%mod;
}
} scanf("%d",&n);
for(int i=;i<=;i++) scanf("%d",&a[i]); memset(dp,,sizeof dp); for(int i=a[];i<=n;i++) dp[][i]=; for(int i=;i>=;i--)
{
sum[i]=sum[i+]+a[i];
for(int j=sum[i];j<=n;j++)
{
for(int k=a[i];k<=j;k++)
{
if(i!=) dp[i][j]=(dp[i][j]+dp[i+][j-k]*c[j][k]%mod)%mod;
else
{
if(j->=) dp[i][j]=(dp[i][j]+dp[i+][j-k]*c[j-][k]%mod)%mod;
}
}
}
} /*
for(int i=9;i>=0;i--)
{
cout<<"---- "<<i<<"----";
for(int j=0;j<=n;j++)
{
cout<<dp[i][j]<<"*";
}
cout<<endl;
}
*/
long long ans=;
for(int i=;i<=n;i++) ans=(ans+dp[][i])%mod; printf("%lld\n",ans); return ;
}

CodeForces 213B Numbers的更多相关文章

  1. Codeforces #55D-Beautiful numbers (数位dp)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  2. codeforces Beautiful Numbers

    来源:http://codeforces.com/problemset/problem/1265/B   B. Beautiful Numbers   You are given a permutat ...

  3. CodeForces 128D Numbers 构造

    D. Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  4. Codeforces 34C-Page Numbers(set+vector+暴力乱搞)

    C. Page Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. [codeforces]Page Numbers <模拟>

    描述: «Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, ...

  6. CodeForces - 83D:Numbers (数学&递归 - min25筛 )

    pro:给定三个整数L,R,P求[L,R]区间的整数有多少个是以P为最小因子的.L,R,P<2e9; sol: 一: 比较快的做法是,用函数的思想递归. 用solve(N,P)表示求1到N有多少 ...

  7. 数位dp整理

    数位dp的思想就在于递归,记录当前的某一个唯一状态,依次递归下去,要注意唯一. 数位dp常设的状态有当前位置,上一数字,是否具有前导零,是否有限制. 1.CodeForces 55DBeautiful ...

  8. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  9. CodeForces 151B Phone Numbers

     Phone Numbers Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Sub ...

随机推荐

  1. 使用Excel快速发送大量的电子邮件

    使用Excel快速发送大量的电子邮件.两个步骤: 1. 准备发送数据: a.) 打开Excel,新Book1.xlsx b.) 填写以下内容. 第一列:接受者,第二列:邮件标题,第三列:文,第四列:附 ...

  2. css优先级机制说明

    原文:css优先级机制说明 首先说明下样式的优先级,样式有三种: 1. 外部样式(External style sheet) 示例: <!-- 外部样式 bootstrap.min.css -- ...

  3. Android AES加密算法,现在实际上

    昨天,老板让我来看看android加密算法.于是在网上找了找,发现AES加密算法.(当然,MD5,BASE64什么http://snowolf.iteye.com/blog/379860这篇文章列举了 ...

  4. Linux内核策略介绍

      Linux内核策略介绍学习笔记   主要内容 硬件 策略 CPU 进程调度.系统调用.中断 内存 内存管理 外存 文件IO 网络 协议栈 其他 时间管理 进程调度 内核的运行时间 系统启动.中断发 ...

  5. WebActivator的实现原理详解

    WebActivator的实现原理详解 文章内容 上篇文章,我们分析如何动态注册HttpModule的实现,本篇我们来分析一下通过上篇代码原理实现的WebActivator类库,WebActivato ...

  6. SpringMVC Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现

    SpringMVC学习系列(12) 完结篇 之 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现 到这里已经写到第12篇了,前11篇基本上把Spring M ...

  7. Code reviews and bad habits

    图文大话编程语言史 投递人 itwriter 发布于 2014-03-07 17:16 评论(2) 有298人阅读  原文链接  [收藏]  « » 英文原文:Code reviews and bad ...

  8. 【转】几点 iOS 开发技巧

    [译] 几点 iOS 开发技巧 原文:iOS Programming Architecture and Design Guidelines 原文来自破船的分享 原文作者是开发界中知晓度相当高的 Mug ...

  9. C语言中数据类型的长度

    面试中C里面int长度经常会被问到,下面总结一下作为资料: 首先看看一般规定: 标准c规定,int长度等于机器字长,short的表示范围不能大于int的表示范围,long的表示范围不能小于int的表示 ...

  10. sql 通过存储过程和自定义类型批量新增数据

    1,建立存储过程 create PROCEDURE [dbo].[p_Company_Insert] @CompanyCollection [CompanyTableType] READONLY AS ...