1193 - Dice (II)

1193 - Dice (II)
Time Limit: 3 second(s)Memory Limit: 32 MB

You have N dices; each of them has K faces numbered from 1 to K. Now you can arrange the N dices in a line. If the summation of the top faces of the dices is S, you calculate the score as the multiplication of all the top faces.

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

Input

Input starts with an integer T (≤ 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 modulo 100000007.

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次点数之和为j的数所有对数的各个的乘积之和。
那么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\n",(dp[n%2][c]%mod+mod)%mod);
55     }
56     return 0;
57 }

 

 

转载于:https://www.cnblogs.com/zzuli2sjy/p/5636173.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
协同过滤算法(Collaborative Filtering)是一种经典的推荐算法,其基本原理是“协同大家的反馈、评价和意见,一起对海量的信息进行过滤,从中筛选出用户可能感兴趣的信息”。它主要依赖于用户和物品之间的行为关系进行推荐。 协同过滤算法主要分为两类: 基于物品的协同过滤算法:给用户推荐与他之前喜欢的物品相似的物品。 基于用户的协同过滤算法:给用户推荐与他兴趣相似的用户喜欢的物品。 协同过滤算法的优点包括: 无需事先对商品或用户进行分类或标注,适用于各种类型的数据。 算法简单易懂,容易实现和部署。 推荐结果准确性较高,能够为用户提供个性化的推荐服务。 然而,协同过滤算法也存在一些缺点: 对数据量和数据质量要求较高,需要大量的历史数据和较高的数据质量。 容易受到“冷启动”问题的影响,即对新用户或新商品的推荐效果较差。 存在“同质化”问题,即推荐结果容易出现重复或相似的情况。 协同过滤算法在多个场景中有广泛的应用,如电商推荐系统、社交网络推荐和视频推荐系统等。在这些场景中,协同过滤算法可以根据用户的历史行为数据,推荐与用户兴趣相似的商品、用户或内容,从而提高用户的购买转化率、活跃度和社交体验。 未来,协同过滤算法的发展方向可能是结合其他推荐算法形成混合推荐系统,以充分发挥各算法的优势。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值