*【CodeForces - 214D 】Numbers (dp,组合数学)

题干:

Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.

There is integer n and array a, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positive integers with the following properties:

  • the number's length does not exceed n;
  • the number doesn't have leading zeroes;
  • digit i (0 ≤ i ≤ 9) occurs in the number at least a[i] times.

Input

The first line contains integer n (1 ≤ n ≤ 100). The next line contains 10 integers a[0], a[1], ..., a[9] (0 ≤ a[i] ≤ 100) — elements of array a. The numbers are separated by spaces.

Output

On a single line print the remainder of dividing the answer to the problem by 1000000007 (109 + 7).

Examples

Input

1
0 0 0 0 0 0 0 0 0 1

Output

1

Input

2
1 1 0 0 0 0 0 0 0 0

Output

1

Input

3
1 1 0 0 0 0 0 0 0 0

Output

36

Note

In the first sample number 9 meets the requirements.

In the second sample number 10 meets the requirements.

In the third sample numbers 10, 110, 210, 120, 103 meet the requirements. There are other suitable numbers, 36 in total.

解题报告:

    dp[i][j]表示:长度为i,用1~j数字所能构成的解的方案数。0的那一位单独处理就可以了、、

AC代码:(62ms)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 4e5 + 5;
const ll mod = 1000000000+7;int n;
int a[15];
ll dp[150][22];
ll C[205][205];
void init() {C[0][0]=1;for(int i=1; i<=100; i++) {C[i][0]=1;for(int j=1; j<=i; j++) {C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;}}
}
int main()
{init();cin>>n;for(int i = 0; i<=9; i++) scanf("%d",a+i);for(int i = a[1]; i<=n; i++) dp[i][1] = 1;//长度为i只包含1的 、for(int i = 1; i<=9; i++) {for(int j = 0; j<=n; j++) {for(int k = a[i]; k<=j; k++) {dp[j][i] = (dp[j][i] + dp[j-k][i-1]*C[j][k])%mod;}}}for(int i = 0; i<=n; i++) {for(int k = a[0]; k<i; k++) {dp[i][0] = (dp[i][0]+dp[i-k][9]*C[i-1][k])%mod;}}ll ans = 0;for(int i = 0; i<=n; i++) ans = (ans + dp[i][0]) % mod;printf("%lld\n",ans);return 0 ;}

关于组合数的求法,还有一种92ms的,,打表到1e5才92ms、、、可以一试啊反正是On的、、

const ll mod = 1000000000+7;
const ll N = 300000+5;
const ll M = 3e5+3;
int n;
ll fac[1000005];            //阶乘
ll inv_of_fac[1000005];        //阶乘的逆元
int a[15];
ll dp[150][12];
ll qpow(ll x,ll n)
{ll ret=1;for(; n; n>>=1){if(n&1) ret=ret*x%mod;x=x*x%mod;}return ret;
}
void init()
{fac[1]=1;for(int i=2; i<=M; i++)fac[i]=fac[i-1]*i%mod;inv_of_fac[M]=qpow(fac[M],mod-2);for(int i=M-1; i>=0; i--)inv_of_fac[i]=inv_of_fac[i+1]*(i+1)%mod;//inv_of_fac[i]=qpow(fac[i],mod-2);//为什么不行啊 //也行
}
ll C(ll a,ll b)
{if(b>a) return 0;if(b==0) return 1;return fac[a]*inv_of_fac[b]%mod*inv_of_fac[a-b]%mod;
}

附:

三套代码的dp思路以后看

#include <bits/stdc++.h>
using namespace std;
#define N 202
#define mod 1000000007typedef long long LL;int n, a[N], s[N];
LL c[N][N], f[N][N], ans;void prepare() {c[0][0] = 1;for (int i = 1; i <= 200; i ++) {c[i][0] = 1;for (int j = 1; j <= i; j ++) c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;}
}
inline LL h(int n, int k) {return c[n+k-1][k];
}
int main() {prepare();scanf("%d", &n);for (int i = 0; i <= 9; i ++) scanf("%d", &a[i]);for (int i = 1; i <= 9; i ++) s[i] = s[i-1] + a[i];int sum = s[9];f[0][0] = 1;for (int i = 1; i <= 9; i ++) {for (int j = s[i-1]; j <= n; j ++) {for (int k = a[i]; k <= n - j; k ++) {f[i][j+k] = (f[i][j+k] + f[i-1][j] * c[j+k][j]) % mod;}}}for (int zero = a[0]; zero <= n; zero ++) {for (int other = sum; other <= n - zero; other ++) {ans = (ans + f[9][other] % mod * h(other, zero)) % mod;}}printf("%I64d\n", ans);return 0;
}

 

代码2

#include<cstdio>
#include<cstring>
int f[15][105];
int d[15];
int n;
int mod=1000000007;
int c[105][105];
int main() {c[0][0]=1;for(int i=1; i<=100; i++) {c[i][0]=1;for(int j=1; j<=i; j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;}scanf("%d",&n);int sum=0;int ans=0;for(int i=0; i<10; i++) {scanf("%d",d+i);sum+=d[i];}for(int i=1; i<=n; i++) {memset(f,0,sizeof(f));f[0][i]=1;for(int j=0; j<10; j++) {for(int k=0; k<=i; k++)if (f[j][k]) {for(int l=d[j]; l<=k; l++)f[j+1][k-l]=(f[j+1][k-l]+1ll*f[j][k]*c[k][l]%mod)%mod;}}ans=(ans+f[10][0])%mod;}n--;if (d[0]) {d[0]--;}for(int i=0; i<=n; i++) {memset(f,0,sizeof(f));f[0][i]=1;for(int j=0; j<10; j++) {for(int k=0; k<=i; k++)if (f[j][k]) {for(int l=d[j]; l<=k; l++)f[j+1][k-l]=(f[j+1][k-l]+1ll*f[j][k]*c[k][l]%mod)%mod;}}//printf("%d\n",f[10][0]);ans=(ans-f[10][0])%mod;}ans=(ans+mod)%mod;printf("%d\n",ans);
}

 

代码3:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;int a[10];
long long f[10][200];
long long C[300][300];
int main() {long long mod=1000000007;for (int i=1; i<=200; i++) {C[i][i]=C[i][0]=1;}C[0][0]=1;for (int i=2; i<=200; i++)for (int j=1; j<i; j++) {C[i][j]=C[i-1][j-1]+C[i-1][j];C[i][j]%=mod;}int n;cin>>n;int tot=0;for (int i=0; i<10; i++) {cin>>a[i];tot+=a[i];}memset(f,0,sizeof(f));for(int i=a[9]; i<=n; i++) {f[9][i]=1;}for (int i=8; i>0; i--) {if (a[i]==0) f[i][0]=f[i+1][0];for (int j=1; j<=n; j++)for (int k=a[i]; k<=j; k++) {f[i][j]+=f[i+1][j-k]*C[j][k];f[i][j]%=mod;}}for (int j=2; j<=n; j++)for (int k=a[0]; k<j; k++) {f[0][j]+=f[1][j-k]*C[j-1][k];f[0][j]%=mod;}// cout<<f[1][1]<<' '<<f[1][2]<<endl;long long ans=0;if (a[0]==0) {ans+=f[1][1];}for (int i=2; i<=n; i++) {ans+=f[0][i];ans%=mod;}cout<<ans%mod<<endl;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441303.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

oracle修改某个数据类型,Oracle 修改某个字段的数据类型三种方式

1.将该列设置为null,再修改其类型(这样会丢失数据)2.最简单的方法&#xff1a;假设你的表名为 tab_targetcreate table test as select * from tab_target whre 12;alter table test modify (col_name number(5));insert into test select * from tab_target;drop table tab_t…

【EOJ Monthly 2018.10 - B】 莫干山奇遇 (思维构造,数学,数组,贪心)(总结)

题干&#xff1a; Time limit per test: 2.0 seconds Memory limit: 512 megabytes 出题人当然是希望出的题目有关 oxx&#xff0c;于是想方设法给题目配上一些有关 oxx 的背景故事&#xff0c;使得它看起来不那么无趣。但有的时候却无法引入合适的小姐姐&#xff0c;使得 o…

有奶瓶的linux系统,用U盘启动BEINI(奶瓶)系统

用U盘启动&#xff1a;奶瓶(beini)这个系统&#xff0c;是一款基于Tiny Core Linux 搭建的无线网络安全测试系统&#xff0c;当然由于它是用来安全测试的系统&#xff0c;因此在安全方面自然有着强大的功能。而且&#xff0c;这个系统非常简便易学&#xff0c;因此现在已经逐渐…

【CodeForces - 227A】Where do I Turn? (计算几何,叉积判断直线拐向)

题干&#xff1a; Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point C and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the dragon. He moved from…

linux内核镜像sd卡,【原创】Linux QT镜像的制作--制作SD卡启动盘

最近买了个新的开发板&#xff0c;原生的是Android操作系统&#xff0c;需要自己少个启动盘&#xff0c;制作LinuxQT操作系统。新的开发板带这个制作的源文件&#xff0c;要先把这个文件拷贝到虚拟机Ubunbtu的共享目录下。打开share文件下显示文件如下&#xff1a;打开文件夹命…

【CodeForces - 227B 】Effective Approach (STL,思维)

题干&#xff1a; Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the numbe…

linux信号值头文件位置,Linux C 信号处理机制

一 . 信号1. 信号&#xff1a;是内核发送给某一进程的一种消息 。2. 信号机制&#xff1a;是Linux系统中用于进程之间相互通信或操作的一种机制。3. 信号的来源&#xff1a;信号来源于内核4. 产生原因&#xff1a; (1)用户通过终端输入 (2)进程执行(3)一个进程调用kill向另一个…

【HDU - 1134 】Game of Connections(JAVA大数加法,卡特兰数)

题干&#xff1a; This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into num…

简述linux系统的安全性,Linux操作系统的安全性有哪些过人之处

01用户/文件权限Linux的敲门砖Linux操作系统的安全性是有目共睹的&#xff0c;相比Windows操作系统&#xff0c;到底Linux有哪些过人之处&#xff1f;这里我们就抛砖引玉&#xff0c;挑选三点重要的特点给大家说明&#xff0c;为什么说Linux操作系统安全性有其他系统无可比拟的…

【qduoj - 夏季学期创新题】C语言课程设计-阶梯问题(dp,高精度大数)

题干&#xff1a; 描述 N级阶梯&#xff0c;人可以一步走一级&#xff0c;也可以一步走两级&#xff0c;求人从阶梯底端走到顶端可以有多少种不同的走法。 输入 一个整数n&#xff0c;代表台阶的阶数。 输出 求人从阶梯底端走到顶端可以有多少种不同的走法&#xff0c;输出结…

linux查询打印机ip,Linux C打印IP地址信息

1、由文件描述符打印IP地址及端口。(参考)#include #include #include #include //由文件描述符打印对应IP地址和端口void PrintAddrByFd(int sockfd){struct sockaddr_in addr_in;socklen_t len sizeof(addr_in);getsockname(sockfd, (struct sockaddr *)&addr_in, &…

【URAL - 1114 】Boxes (dp,组合数学)

题干&#xff1a; N boxes are lined up in a sequence (1 ≤ N ≤ 20). You have A red balls and B blue balls (0 ≤ A ≤ 15, 0 ≤ B ≤ 15). The red balls (and the blue ones) are exactly the same. You can place the balls in the boxes. It is allowed to put in a…

linux强行卸载qt,Linux下卸载QT SDK

unbuntu下卸载QT方法一&#xff1a;you can remove it like this, those developers should add this somewhere ! like next to the download textlinuxmint ~ # cd /optlinuxmint opt # lsqtsdk-2010.04linuxmint opt # sudo ./qtsdk-2010.04/bin/uninstalllinuxmint opt #方…

【CodeForces - 227C】Flying Saucer Segments (思维)

题干&#xff1a; An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives dont even have antennas on their heads!). The flying saucer, on which the brave pioneers set off, consists of three sections. …

清楚linux缓存文件,Linux删除文件 清除缓存

相信很多测试 经常会经历开发叫你清除缓存这种事。那我们要怎么清呢&#xff1f;一、首先&#xff0c;确认你要清除的缓存在哪个目录下&#xff0c;然后切换到该目录下&#xff0c;比如 我现在知道我的的缓存目录是在newerp这个目录下&#xff0c;则如图二、然后 执行命令 rm -…

【HDU - 2546】饭卡 (dp,0-1背包,贪心思想)

电子科大本部食堂的饭卡有一种很诡异的设计&#xff0c;即在购买之前判断余额。如果购买一个商品之前&#xff0c;卡上的剩余金额大于或等于5元&#xff0c;就一定可以购买成功&#xff08;即使购买后卡上余额为负&#xff09;&#xff0c;否则无法购买&#xff08;即使金额足够…

linux的程序员计算器,linux中的计算器

windows系统安装时会自带计算器&#xff0c;在cmd中运行calc即可打开。那么linux系统中有没有计算器呢&#xff1f;答案是肯定的。linux下的图形计算器linux系统一般也会默认安装一个图形界面的计算器&#xff0c;例如红帽系统默认安装的是gcalctool。假如在一个图形桌面环境中…

【HDU - 薛猫猫杯程序设计网络赛】【题解】

A 爬山 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0 Accepted Submission(s): 0 Problem Description 小Z准备去爬山&#xff0c;在他的面前有N座山&#xff0c;每座山都有对应的高度。他想选择两座高…

win10 linux安卓模拟器,genymotion安卓模拟器在Window10中使用的问题

最近一段时间&#xff0c;把系统升级到了win10&#xff0c;然后悲催的事情出现了&#xff0c;genymotion挂了&#xff0c;根本就不能启动&#xff0c;而且还是2.6版本的genymotion&#xff0c;下面我把遇到的问题总结一下&#xff1a;首先&#xff0c;在我的win10系统中&#x…

【CodeForces - 706C】Hard problem(dp,字典序)

题干&#xff1a; Vasiliy is fond of solving different tasks. Today he found one he wasnt able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical orde…