CodeForces 213B Numbers
$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的更多相关文章
- Codeforces #55D-Beautiful numbers (数位dp)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- codeforces Beautiful Numbers
来源:http://codeforces.com/problemset/problem/1265/B B. Beautiful Numbers You are given a permutat ...
- CodeForces 128D Numbers 构造
D. Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces 34C-Page Numbers(set+vector+暴力乱搞)
C. Page Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- [codeforces]Page Numbers <模拟>
描述: «Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, ...
- CodeForces - 83D:Numbers (数学&递归 - min25筛 )
pro:给定三个整数L,R,P求[L,R]区间的整数有多少个是以P为最小因子的.L,R,P<2e9; sol: 一: 比较快的做法是,用函数的思想递归. 用solve(N,P)表示求1到N有多少 ...
- 数位dp整理
数位dp的思想就在于递归,记录当前的某一个唯一状态,依次递归下去,要注意唯一. 数位dp常设的状态有当前位置,上一数字,是否具有前导零,是否有限制. 1.CodeForces 55DBeautiful ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- CodeForces 151B Phone Numbers
Phone Numbers Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Sub ...
随机推荐
- mysql基础之基本数据类型
原文:mysql基础之基本数据类型 列类型学习 mysql三大列类型 整型 Tinyint/ smallint/ mediumint/int/ bigint(M) unsigned zerofill ...
- Android项目---HtmlParse
在解析网站上的内容的时候,总会出现很多html的标签,一般在遇到这种数据的时候,就可以用上Html 如: content.setText(Html.fromHtml("<html> ...
- angularjs执行流程
angularjs源码分析之:angularjs执行流程 angularjs用了快一个月了,最难的不是代码本身,而是学会怎么用angular的思路思考问题.其中涉及到很多概念,比如:directi ...
- DEBUG不能进断点 “exited with code -1073741515”
需要把相关的DLL文件加入到项目对应的DEBUG路径下 IDE :Qt Creator 系统:Win7
- 【分享】改变未来的九大算法[pdf][清晰扫描版]
[下载地址]http://www.colafile.com/file/1179688 图书信息:中文名: 改变未来的九大算法作者: 约翰·麦考密克译者: 管策图书分类: 软件资源格式: PDF版本: ...
- 2008技术内幕:T-SQL语言基础
2008技术内幕:T-SQL语言基础 单表查询摘记 这里的摘抄来自<Microsoft SQL Server 2008技术内幕:T-SQL语言基础>,书中用到的案例数据库是这个 TSQLF ...
- MongoDB:利用官方驱动改装为EF代码风格的MongoDB.Repository框架 六:支持多数据库操作
本次主要内容:修正MongoDB.Repository框架对多数据库的支持. 在之前的五篇文章中对MongoDB.Repository框架做了简单的介绍是实现思路.之前是考虑MongoDB.Repos ...
- Debian 7.1设置中文环境
之前在Chinaunix上看过一个人写过博客,是关于介绍Debian设置中文环境的,在这里我针对Debian 7来补全一下. Debian是非常经典而优秀的Linux发行版了,Debian是个很大的家 ...
- [转]Inspecting Obj-C parameters in gdb
Since the addition of i386 and x86_64 to the Mac OS’s repertoire several years back, remembering whi ...
- 探讨 : Host在IIS上的WCF Service的执行方式
一个WCF请求由两个线程来完成 运行在IIS上的WCF service, 你可能会注意到一个比较有趣的现象. 当WCF service接收到一个请求时, 这个请求实际上会有两个线程在执行这个请求. 一 ...