1 条题解
-
0
C++ :
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define N 1000007 #define o 102 using namespace std; int a[o],f[o][o]; int n,m; int main() { cin>>n>>m; for(int i=1;i<=n;i++)cin>>a[i]; f[0][0]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=m;j++) { for(int k=0;k<=a[i];k++) { if(j-k>=0) f[i][j]=(f[i][j]+f[i-1][j-k])%N; else break; } } } cout<<f[n][m]; return 0; }
Pascal :
var a:array[0..100,0..100]of longint; i,j,k,m,n,s,t:longint; w:array[0..100]of longint; begin readln(n,m); for i:=1 to n do read(w[i]); for i:=1 to w[1] do a[1,i]:=1; for i:=0 to m do a[i,0]:=1; for i:=2 to m do for j:=1 to m do begin s:=0; for k:=j-w[i] to j do if k>=0 then s:=(s+a[i-1,k]) mod 1000007; a[i,j]:=s; end; writeln(a[n,m]); end.
- 1
信息
- ID
- 302
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- 递交数
- 5
- 已通过
- 3
- 上传者