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 ...
随机推荐
- xheditor 进阶
xhEditor提供两种方式初始化编辑器: 方法1:利用class属性来初始化和传递各种初始化参数,例: class="xheditor {skin:'default'}" 方法 ...
- bootstrap导航菜单,手机和PC端
源代码 <!DOCTYPE html> <html> <head lang="en"> <meta name="viewport ...
- Linux环境下搭建php开发环境的操作步骤
本文主要记载了通过编译方式进行软件/开发环境的安装过程,其他安装方式忽略! 文章背景: 因为php和Apache等采用编译安装方式进行安装,然而编译安装方式,需要c,c++编译环境, 通过apt方式安 ...
- Android项目---语言适配
android多国语言文件夹 android多国语言文件夹文件汇总如下:(有些语言的书写顺序可能跟中文是相反的) 中文(中国):values-zh-rCN 中文(台湾):values-zh-rTW 中 ...
- 学习Python编程的11个精品资源
本文由 伯乐在线 - atupal 翻译自 Alex Ivanovs.欢迎加入技术翻译小组.转载请参见文章末尾处的要求. 用 Python 写代码并不难,事实上,它一直以来都是被声称为最容易学习的编程 ...
- NLP startup material
The Association for Computational Linguistics(ACL,URL:http://aclweb.org/) Computational Linguistics( ...
- IOS UI 第三篇:基本UI
工厂模式: .h文件: #import <Foundation/Foundation.h>typedef enum{ QFRed, QFYellow, QFBlu ...
- Javascript模块化编程之难处
接着上一篇“Javascript模块化编程之Why”说起,Javascript担子重了之后程序也就复杂了.在大把语言都模块化编程的形势下,Javascript也不可能袖手旁观啊,毕竟这是一条经过实践检 ...
- linux下telnet mysql的3306断口,提示Can't connect to MySQL server on localhost (110)
新购买的阿里云ECS服务器,食用lnmp环境,安装完毕后,telnet localhost 3306提示Can't connect to MySQL server on localhost (110) ...
- web前端学习笔记
web前端学习笔记(CSS盒子的定位) 相对定位 使用相对定位的盒子的位置常以标准流的排版方式为基础,然后使盒子相对于它在原本的标准位置偏移指定的距离.相对定位的盒子仍在标准流中,它后面的盒子仍以标准 ...