Problem

给出Ai(i∈[0,9])。表示每一个数字至少须要出现多少次。问有多少个数满足下面三个条件:1. 数至多有N位;2. 数不含有前导0;3. 每一个数 i 出现的次数不少于Ai(mod 1e9+7)

Limits

TimeLimit(ms):2000

MemoryLimit(MB):256

N∈[1,100]

Ai∈[0,100]

Look up Original Problem From here

Solution

实际上是一种填数、计数统计的问题。

考虑填0的情况。在此基础上。考虑填1的情况。…。最后考虑填9的情况。

因为不可含有前导0,最好还是先枚举如果第一个数字,而剩下的N-1位数字进行填数。设dp[i][j]表示当前填下的这个数为 i,数的长度是 j 时有多少个数满足题意。

转移方程:dp[now][i+j]=dp[now][i+j]+dp[now−1][j]×Cin−j。统计答案,ans=∑nj=0(dp[9][j]Cn−jn)。除法不满足取模运算。用逆元解决。

Complexity

TimeComplexity:O(9⋅9⋅N2)

MemoryComplexity:O(N2)

My Code

//Hello. I'm Peter.
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
#define peter cout<<"i am peter"<<endl
#define randin srand((unsigned int)time(NULL))
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define input freopen("data.txt","r",stdin)
#define gsize(a) (int)a.size()
#define len(a) (int)strlen(a)
#define slen(s) (int)s.length()
#define clr(a) memset(a,0,sizeof(a))
#define clr_queue(q) while(!q.empty()) q.pop()
#define clr_stack(s) while(!s.empty()) s.pop()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define dep(i, a, b) for (int i = a; i > b; i--)
#define repin(i, a, b) for (int i = a; i <= b; i++)
#define depin(i, a, b) for (int i = a; i >= b; i--)
#define esp 1e-6
#define MAXN
#define N 200
#define M
const ll mod=1e9+7;
ll C[N][N],ans,dp[15][N];
int n,a[N],sum;
void init_C(){
clr(C);
rep(i,0,N){
C[i][0]=1;
}
rep(i,1,N){
rep(j,1,N){
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
}
}
ll quick_power(ll x,ll y){
if(!y) return 1;
ll res=quick_power(x,y>>1);
res=res*res%mod;
if(y%2) res=res*x%mod;
return res;
}
int main(){
init_C();
ans=0;
scanf("%d",&n);
rep(i,0,10){
scanf("%d",a+i);
}
repin(de,1,9){
a[de]-=1;
n-=1;
repin(i,0,9){
repin(j,0,n){
dp[i][j]=0;
}
}
repin(i,0,n){
if(i>=a[0]) dp[0][i]=C[n][i];
}
repin(now,1,9){
repin(i,0,n){
if(i<a[now]) continue;
repin(j,0,n){
if(i+j>n || !dp[now-1][j]) continue;
dp[now][i+j]=(dp[now][i+j]+dp[now-1][j]*C[n-j][i])%mod;
}
}
}
repin(i,0,n){
// ans=(ans+dp[9][i]/C[n][n-i]); 不能直接求。转化为逆元来做。
ans=(ans+dp[9][i]*quick_power(C[n][n-i],mod-2))%mod;
}
n+=1;
a[de]+=1;
}
printf("%lld\n",ans);
}

Codeforces Round #131 Div1 B的更多相关文章

  1. Codeforces Round #543 Div1题解(并不全)

    Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...

  2. Codeforces Round #545 Div1 题解

    Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...

  3. Codeforces Round #539 Div1 题解

    Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...

  4. [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】

    题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...

  5. Codeforces Round #131 (Div. 1) B. Numbers dp

    题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...

  6. Codeforces Round #131 (Div. 2) B. Hometask dp

    题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...

  7. Codeforces Round #131 (Div. 2) E. Relay Race dp

    题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...

  8. Codeforces Round #253 DIV1 C 馋

    http://codeforces.com/contest/442/problem/C 题意非常easy,基本上肯定有坑坑洼洼的样子.看题目案例,从第三个跟第二个没有凹的案例来看的话,多写几个以及多画 ...

  9. Codeforces Round #413 (Div1 + Div. 2) C. Fountains(树状数组维护最大值)

    题目链接:https://codeforces.com/problemset/problem/799/C 题意:有 c 块硬币和 d 块钻石,每种喷泉消耗硬币或钻石中的一种,每个喷泉有一个美丽值,问建 ...

随机推荐

  1. Java中final关键字概述

    使用final修饰过的变量都不可以改变: 1.final修饰变量 恒定不变的属性,可以用final关键字来修饰: 变量名建议全部使用大写 final修饰的变量不能改变,如果程序中重新赋值,编译报错 例 ...

  2. 深入理解java虚拟机-00

    这本书买了有两年了,只有买回来翻了两页...今天电脑有点卡,游戏玩不了了,就来看看这本书. 首先看了序言,这本书是第二版,讲解的jdk版本是1.7,现在公司用的1.8,而且1.8的改动也挺大的,不过在 ...

  3. Java 基本语法---Java方法

    Java 基本语法---Java方法 0.概述 方法:就是用来解决一类问题的代码的有序组合,是一个功能模块: 在方法部分,只使用对象名词调用方法: Scanner sc = new Scanner(S ...

  4. python3.6连接oracle数据库

    下载cx_Oracle模块模块: https://pypi.python.org/pypi/cx_Oracle/5.2.1#downloads 这里下载的是源码进行安装 [root@oracle or ...

  5. KnockoutJs学习笔记(九)

    由于component binding部分的内容更为复杂一些,所以这部分我暂时跳过,先学习click binding部分. click binding不仅可以作用于button.input.a等元素, ...

  6. Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)

    思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. #include<bits/stdc++.h> #define ...

  7. Linux 配置mail发送邮件

    一.在/etc/mail.rc下添加如下内容 set from=lipingchang@pystandard.com set smtp=smtp.pystandard.com set smtp-aut ...

  8. 【Java】 归并排序的非递归实现

    归并排序可以采用递归方法(见:归并排序),但递归方法会消耗深度位O(longn)的栈空间,使用归并排序时,应该尽量使用非递归方法.本文实现了java版的非递归归并排序. 更多:数据结构与算法合集 思路 ...

  9. Java 类的继承详解

    /*文章中用到的代码只是一部分,需要完整代码的可通过邮箱联系我1978702969@qq.com*/ 在面向对象的语言中如C++和JAVA,都有一个比较重要的机制——类的继承.这里将对JAVA中的类的 ...

  10. 【Ray Tracing The Next Week 超详解】 光线追踪2-1

     Preface 博主刚放假回家就进了医院,今天刚完事儿,来续写第二本书  Ready 我们来总结一下上一本书的笔记中我们的一些规定 1. 数学表达式 我们采用小写粗黑体代表向量,大写粗黑体代表矩阵, ...