日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

1193

發(fā)布時間:2024/1/4 综合教程 26 生活家
生活随笔 收集整理的這篇文章主要介紹了 1193 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1193 - Dice (II)

PDF (English) Statistics Forum
Time Limit:3 second(s) Memory Limit:32 MB

You haveNdices; each of them hasKfaces numbered from1toK. Now you can arrange theNdices in a line. If the summation of the top faces of the dices isS, you calculate the score as the multiplication of all the top faces.

Now you are givenN, K, S; you have to calculate the summation of all the scores.

Input

Input starts with an integerT (≤ 25), denoting the number of test cases.

Each case contains three integers:N (1 ≤ N ≤ 1000) K (1 ≤ K ≤ 1000) S (0 ≤ S ≤ 15000).

Output

For each case print the case number and the result modulo100000007.

Sample Input

Output for Sample Input

5

1 6 3

2 9 8

500 6 1000

800 800 10000

2 100 10

Case 1: 3

Case 2: 84

Case 3: 74335590

Case 4: 33274428

Case 5: 165


PROBLEM SETTER: JANE ALAM JAN
思路:和1145差不多。
dp[i][j]表示前i次點數(shù)之和為j的數(shù)所有對數(shù)的各個的乘積之和。
那么dp[i][j]=dp[i-1][j-1]+dp[i-1][j-2]*2+....dp[i-1][j-k]*k;
這樣的復雜度是n*n*n;這樣是過不了的;
那么dp[i][j+1]=dp[i-1][j]+dp[i-1][j-1]*2+dp[i-1][j-2]*3+....dp[i-1][j-k+1]*k;
那么dp[i][j+1]=dp[i][j-1]+dp[i-1][j-1]+sum[j-2]-sum[max(0,j-1-m)]-dp[i-1][max(0,j-m-1)]*m;
那么我們每次維護一個dp[i][j]的前綴和就可以了。

 1 #include<stdio.h>
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<string.h>
 5 #include<math.h>
 6 #include<stdlib.h>
 7 #include<queue>
 8 using namespace std;
 9 typedef long long LL;
10 LL dp[2][15005];
11 const int mod=100000007;
12 LL sum[15005];
13 int main(void)
14 {
15     int i,j,k;
16     scanf("%d",&k);
17     int s;
18     int n,m,c;
19     for(s=1; s<=k; s++)
20     {
21         scanf("%d %d %d",&n,&m,&c);
22         memset(dp,0,sizeof(dp));
23         memset(sum,0,sizeof(sum));
24         for(i=1; i<=m; i++)
25         {
26             dp[1][i]=i;
27             dp[1][i]%=mod;
28             sum[i]=(sum[i-1]+dp[1][i])%mod;
29         }
30         for(i=m+1;i<=c;i++)
31             sum[i]=sum[i-1];
32         for(i=2; i<=n; i++)
33         {
34             int uu=(i)%2;
35             int kk=(i+1)%2;
36             for(j=0; j<i; j++)
37             {
38                 dp[uu][j]=0;
39             }
40             for(j=i;j<=c; j++)
41             {
42       dp[uu][j]=((dp[kk][j-1]+dp[uu][j-1])%mod+(sum[j-2]-sum[max(0,j-1-m)])%mod-dp[kk][max(0,j-m-1)]*m%mod)%mod;
43                 dp[uu][j]%=mod;
44                 dp[uu][j]+=mod;
45                 dp[uu][j]%=mod;
46             }
47             for(j=1; j<=c; j++)
48             {
49                 sum[j]=sum[j-1]+dp[uu][j];
50                 sum[j]%=mod;
51             }
52         }
53         printf("Case %d: ",s);
54         printf("%lld
",(dp[n%2][c]%mod+mod)%mod);
55     }
56     return 0;
57 }

油!油!you@

總結

以上是生活随笔為你收集整理的1193的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。