zoukankan      html  css  js  c++  java
  • Dice (II) (DP)唉,当时没做出来

    Time Limit: 3000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

    []   [Go Back]   [Status]  

    Description

    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

    5

    1 6 3

    2 9 8

    500 6 1000

    800 800 10000

    2 100 10

    Sample Output

    Case 1: 3

    Case 2: 84

    Case 3: 74335590

    Case 4: 33274428

    Case 5: 165

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 using namespace std;
     5 #define mod 100000007
     6 int dp[2][15001];
     7 int main()
     8 {
     9     long long t,r,n,k,s,j,kk,i;
    10     cin>>t;
    11     for(r=1; r<=t; r++)
    12     {
    13         memset(dp,0,sizeof(dp));
    14         cin>>n>>k>>s;
    15         for(j=1; j<=k; j++)
    16             dp[1][j]=j;
    17         long long size,sum,jia;
    18         for(i=2; i<=n; i++)
    19         {
    20             size=i*k>s?s:i*k;
    21             sum=0,jia=0;
    22             memset(dp[i&1],0,sizeof(dp[i&1]));
    23             for(j=i-1; j>=1&&i-j<=k; j--)
    24             {
    25                 jia+=dp[(i-1)&1][j];
    26                 sum+=dp[(i-1)&1][j]*(i-j);
    27             }
    28             for(j=i; j<=size; j++)
    29             {
    30                 dp[i&1][j]=sum%mod;
    31                 if(j-k>=1)
    32                 {
    33                     jia-=dp[(i-1)&1][j-k];
    34                     sum-=dp[(i-1)&1][j-k]*k;
    35                 }
    36                 jia+=dp[(i-1)&1][j];
    37                 sum+=jia;
    38             }
    39         }
    40         printf("Case %d: ",r);
    41         printf("%d
    ",dp[n&1][s]);
    42     }
    43 }
    View Code
  • 相关阅读:
    js上移、下移排序 效果
    如何为平板打造完美的网站页面?
    [BUUOJ]刮开有奖reverse
    [0CTF 2016]piapiapia
    [TSCTFJ 2019]bypass
    [安洵杯 2019]easy_serialize_php
    [TSCTFJ] relax
    c#访问网页
    DNN 数据访问
    c#访问数据库
  • 原文地址:https://www.cnblogs.com/ERKE/p/3588601.html
Copyright © 2011-2022 走看看