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

 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
LL dp[maxn][maxn] = {},ret;
int d[maxn],n,sum;
int main(){
for(int i = ; i < ; ++i){
for(int j = ; j <= ; ++j)
for(int k = ; k <= j; ++k)
dp[i][j] += dp[i-][j - k];//i个评委共打出j分的总数
}
while(scanf("%d",&n),n){
for(int i = sum = ; i < n; ++i){
scanf("%d",d+i);
sum += d[i];
}
ret = ;
for(int i = ; i < sum; ++i) ret += dp[n][i];//小于
for(int i = ; i < n; ++i){//等于
for(int j = ; j < d[i]; ++j)
ret += dp[n-i-][sum - j];//第1个评委打j分,剩下n-i-1个评委共打sum - j分
sum -= d[i];
}
printf("%lld\n",ret);
}
return ;
}

最新文章

  1. c语言编程
  2. PHP文件操作 之读取一个文件(以二进制只读的方式打开)
  3. Datable 排序
  4. 使用JS制作一个鼠标可拖的DIV(四)——缩放
  5. 2、.net NVelocity中原生javascript ajax封装使用
  6. SQL Server查看所有表大小,所占空间
  7. nginx File not found 错误分析与解决方法
  8. [置顶] 无名管道的C++封装
  9. php的laravel框架使用心得
  10. 还在用Synchronized?Atomic你了解不?
  11. js拼接字符串后swiper不能动的解决方案
  12. mac IntelliJ Idea添加schema和dtd约束提示
  13. React中props
  14. xen 配置vm 跟随xen server一起启动
  15. 递归和非递归分别实现求n的阶乘
  16. EBS 多sheet页Excel动态报表开发过程
  17. Elasticsearch 系列3 --- Elasticsearch配置
  18. Jq_input file标签上传图片到服务器
  19. Java 存储和读取 oracle CLOB 类型字段的实用方法
  20. win32多线程-新版本MtVerify.h

热门文章

  1. Linux下PHP开启Oracle支持(oci8)
  2. 自己封装js组件 - 初级
  3. Can not Stop-Computer in powershell 6.0
  4. 5.IntellijIDEA常用快捷键总结
  5. java 类和对象1
  6. Android-加载大图避免OOM
  7. 提高realm存储速率
  8. VMware Workstation pro14 虚拟机下安装CentOS6.8图文教程
  9. sql的系统关键字的概述
  10. Qihoo 360 altas 实践