$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. WinForm中回车键实现文本框之间的跳转

    利用窗体的KeyPreView .设置KeyPreView = true 设置窗体的KeyPreView 属性为True后,那么窗体内的子控件响应KeyPress事件(或其他事件)之前,会先响应窗体的 ...

  2. Ibatis 返回datatable数据类型案例

    /// <summary> /// 查询实体 [DataSet数据集] /// </summary> /// <param name="statementNam ...

  3. 松瀚SN8P2501 定时器初始化程序--汇编源码

    /* 松瀚 SN8P2501B 定时器初始化程序 */ INI_IRQ: ;定时器T0初始化 MOV A, #01100000b ;定时器模式Fcpu/4 16M/4/4=1M 1U计一次 B0MOV ...

  4. Lambda表达式、依赖倒置

    ASP.NET MVC学前篇之Lambda表达式.依赖倒置 ASP.NET MVC学前篇之Lambda表达式.依赖倒置 前言 随着上篇文章的阅读,可能有的朋友会有疑问,比如(A.Method(xxx= ...

  5. boost------signals2的使用2(Boost程序库完全开发指南)读书笔记

    1.应用于观察者模式 本小节将使用signals2开发一个完整的观察者模式示例程序,用来演示信号/插槽的用法.这个程序将模拟一个日常生活场景:客人按门铃,门铃响,护士开门,婴儿哭闹. Ring.h: ...

  6. MVC AuthorizeAttribute 动态授权

    开发中经常会遇到权限功能的设计,而在MVC 下我们便可以使用重写 AuthorizeAttribute 类来实现自定义的权限认证 首先我们的了解 AuthorizeAttribute 下面3个主要的方 ...

  7. [原]iOS Makefile Template

    export DEVELOPER_DIR := $(shell xcode-select --print-path) PLATFORM="$(DEVELOPER_DIR)/Platforms ...

  8. Hook SSDT中NtCreateProcessEx

    #ifdef __cplusplus extern "C" { #endif #include <ntddk.h> #ifdef __cplusplus } #endi ...

  9. 【Lotus Notes】邮件获取

    public class LotusManager { public static int bodyMaxLength, length; public static List<Entity.Lo ...

  10. myeclipse maven编译出错

    从.net 到java  快一年了.这一年学了很多东西.从开发角度来说俩个语言查不到.部署上差异较大.不过java处理问题上确实不太统一.好多问题在网上没有正确的回答.刚换台式机发现 mvn inst ...