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
#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 ;
}
CSUOJ 1635 Restaurant Ratings的更多相关文章
- UVALive - 6872 Restaurant Ratings 数位dp
题目链接: http://acm.hust.edu.cn/vjudge/problem/113727 Restaurant Ratings Time Limit: 3000MS 题意 给你一个长度为n ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- POJ 1635 树的最小表示法/HASH
题目链接:http://poj.org/problem?id=1635 题意:给定两个由01组成的串,0代表远离根,1代表接近根.相当于每个串对应一个有根的树.然后让你判断2个串构成的树是否是同构的. ...
- csuoj 1511: 残缺的棋盘
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec 内存限制: 128 MB 题目描述 输入 ...
- 回文串+回溯法 URAL 1635 Mnemonics and Palindromes
题目传送门 /* 题意:给出一个长为n的仅由小写英文字母组成的字符串,求它的回文串划分的元素的最小个数,并按顺序输出此划分方案 回文串+回溯:dp[i] 表示前i+1个字符(从0开始)最少需要划分的数 ...
- Flo's Restaurant[HDU1103]
Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- NBUT 1635 Explosion(最小顶点覆盖)
[1635] Explosion 时间限制: 10000 ms 内存限制: 65535 K 问题描述 there is a country which contains n cities connec ...
- [POJ 1635] Subway tree systems (树哈希)
题目链接:http://poj.org/problem?id=1635 题目大意:给你两棵树的dfs描述串,从根节点出发,0代表向深搜,1代表回溯. 我刚开始自己设计了哈希函数,不知道为什么有问题.. ...
- Codeforces Testing Round #12 B. Restaurant 贪心
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...
随机推荐
- 9、包、访问控制、import、static、static代码块、final、抽象类、接口、instanceof、多态
1.包 三级命名:公司的尾缀(com).公司名字(baidu).业务(Sale) java.lang:默认包:String.Math,Object,System java.util:工具包 java. ...
- Android Jni 调用
Chap1:JNI完全手册... 3 Chap2:JNI-百度百科... 11 Chap 3:javah命令帮助信息... 16 Chap 4:用javah产生一个.h文件... 17 Chap5:j ...
- DNS RR代码和含义
记录类型 代码 号码 定义的 RFC 描述 功能 A 1 RFC 1035 IP 地址记录 传回一个 32 比特的 IPv4 地址,最常用于映射主机名称到 IP地址,但也用于DNSBL(RFC 110 ...
- 86.express里面的app.configure作用
以下摘自 express 3.0 的 文档 app.configure([env], callback) Conditionally invoke callback when env matches ...
- 关于nth-of-type和nth-child的关系
一开始写样式的时候喜欢全部元素都来个class,后面发现这样一个页面下来很多个class,起名字起到发慌,然后老师说该多用 逻辑关系来写样式,就是这种第几个孩子啊这种,不知道你们有没有这种烦恼,要用的 ...
- Oracle 建表
-- Create table create table STUDENT ( sno ) not null, sname ) not null, ssex ) not null, sbirthday ...
- Kinect 人机交互开发实践
Kinect for Windows SDK 骨骼追踪 —— 对在Kinect视野范围内移动的一个或两个人进行骨骼追踪,可追踪到人体的20个节点 深度摄像头 —— 通过深度传感器获取到视野内的环境三维 ...
- vue分页组件火狐中出现样式问题
分页的操作到了火狐浏览器会样式 怎么解决? 其实就是将input的type属性变成了text,因为number属性会变成上下的小箭头
- vue 学习笔记1 入门
可以在 JSFiddle上在线学习vue 注意:所演示的示例,都是在JS中将Vue实例绑定至HTML中的指定元素,然后再通过Vue实例中data内的属性或者methods中的方法,来对所绑定元素的子元 ...
- Python内存分配器(如何产生一个对象的过程)
目录 内存分配器 Python分配器分层 第零层--通用的基础分配器 第一层--低级内存分配器 内存结构 arena pool new arena usable_arenas和unused_arena ...