CSUOJ 1635 Restaurant Ratings

1635: Restaurant Ratings

Time Limit: 1 Sec  Memory Limit: 128 MB

Description

A famous travel web site has designed a new restaurant rating system. Each restaurant is rated by one of n (1 n 15) critics, each giving the restaurant a nonnegative numeric rating (higher score means better). Some of these critics are more influential than others. The restaurants in each city are ranked as follows. First, sum up the ratings given by all the critics for a restaurant. A restaurant with a higher total sum is always better than one with a lower total sum. For restaurants with the same total sum, we rank them based on the ratings given by critic 1. If there is a tie, then we break ties by the ratings by critic 2, etc. A restaurant owner received the ratings for his restaurant, and is curious about how it ranks in the city. He does not know the ratings of all the other restaurants in the city, so he would estimate this by computing the maximum number of different ratings that is no better than the one received by the restaurant. You are asked to write a program to answer his question.

 

Input

The input consists of a number of cases. Each case is specified on one line. On each line, the first integer is
n, followed by n integers containing the ratings given by the n critics (in order). You may assume that the
total sum of ratings for each restaurant is at most 30. The input is terminated by a line containing n = 0.

 

Output

For each input, print the number of different ratings that is no better than the given rating. You may assume
that the output fits in a 64-bit signed integer.

 

Sample Input

1 3
2 4 3
5 4 3 2 1 4
0

Sample Output

4
33
10810

HINT

 

Source

 

解题:dp

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn = 35;
 5 LL dp[maxn][maxn] = {1},ret;
 6 int d[maxn],n,sum;
 7 int main(){
 8     for(int i = 1; i < 16; ++i){
 9         for(int j = 0; j <= 30; ++j)
10             for(int k = 0; k <= j; ++k)
11                 dp[i][j] += dp[i-1][j - k];//i个评委共打出j分的总数
12     }
13     while(scanf("%d",&n),n){
14         for(int i = sum = 0; i < n; ++i){
15             scanf("%d",d+i);
16             sum += d[i];
17         }
18         ret = 1;
19         for(int i = 0; i < sum; ++i) ret += dp[n][i];//小于
20         for(int i = 0; i < n; ++i){//等于
21             for(int j = 0; j < d[i]; ++j)
22                 ret += dp[n-i-1][sum - j];//第1个评委打j分,剩下n-i-1个评委共打sum - j分
23             sum -= d[i];
24         }
25         printf("%lld\n",ret);
26     }
27     return 0;
28 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4553940.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值