CSU1635: Restaurant Ratings

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


题意:有n个评委打分,餐馆所得的分数是所有评委给分的总和,要求分数不高于这个分数的最大数量,在总分相同的情况下,看第一个评委分高的排名靠前,第一个相同,那么比较第二个,如此类推

思路:首先dp求出每种数量的评委对应不同总分的数量,然后再在计算中加上所有总分低的数量,还有枚举各个评委

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

#define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 25
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8

LL dp[35][35];
int a[35];

int main()
{
    int n,i,j,k;
    dp[0][0] = 1;
    UP(i,1,15)
    {
        UP(j,0,30)
        {
            UP(k,0,j)
            {
                dp[i][j]+=dp[i-1][j-k];
            }
        }
    }
    W(~scanf("%d",&n))
    {
        if(!n) break;
        int sum = 0;
        LL ans = 1;
        UP(i,0,n-1)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        UP(i,0,sum-1)//总分低于sum的数量
        {
            ans+=dp[n][i];
        }
        UP(i,0,n-1)//枚举各个评委
        {
            UP(j,0,a[i]-1)
            {
                ans+=dp[n-1-i][sum-j];
            }
            sum-=a[i];
        }
        printf("%lld\n",ans);
    }

    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值