zoukankan      html  css  js  c++  java
  • 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
    ",ret);
    26     }
    27     return 0;
    28 }
    View Code
  • 相关阅读:
    Android ADB 基本命令
    Android Studio修改包名
    Android开发之SurfaceView
    Android呼吸灯效果实现
    Android xml 绘制图形
    设计模式--代理模式C++实现
    设计模式--建造者模式C++实现
    设计模式--模板方法模式C++实现
    设计模式--抽象工厂模式C++实现
    设计模式---工厂方法C++实现
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4553940.html
Copyright © 2011-2022 走看看