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 ...
随机推荐
- 2、Python列表和元组
2.Python序列 序列是一种数据存储方式,类似于C语言的数组.简单的说序列是一块用来存储多个值的连续内存空间,同一个序列的元素通常是相关的. Python中常用的序列结构有列表.元组.字典.字符串 ...
- Android笔记---点击事件的四种写法
Android 点击事件的四种写法: 1. 以内部类的形式实现 OnClickListener 接口.定义点击事件 class MainActivity extents Activity{ // .. ...
- sklearn.preprocessing OneHotEncoder——仅仅是数值型字段才可以,如果是字符类型字段则不能直接搞定
>>> from sklearn.preprocessing import OneHotEncoder >>> enc = OneHotEncoder() > ...
- [luogu P2586] GCD 解题报告 (莫比乌斯反演|欧拉函数)
题目链接:https://www.luogu.org/problemnew/show/P2568#sub 题目大意: 计算$\sum_{x=1}^n\sum_{y=1}^n [gcd(x,y)==p ...
- Traversal with a for loop
A lot of computations involve processing a string one character at a time. Often they start at the b ...
- Linux-php安装mongodb
Linux-php安装mongodb 标签(空格分隔): php 安装mongodb 1 下载解压 下载压缩包 :https://www.mongodb.com/download-center?jmp ...
- 131.lambda表达式小结
C++ 11中的Lambda表达式用于定义并创建匿名的函数对象,以简化编程工作.Lambda的语法形式如下:[函数对象参数](操作符重载函数参数) mutable或exception声明->返回 ...
- SSRS 报表 递归列表
SSRS 报表 递归列表 .需要数据集合中两个必备字段 ID PID 1.添加数据集合,在图上标记的地方点击右键添加数据集合,根据需求自己编写 2.点击插入选项卡 中的 矩阵 有两种方式 一种是 矩 ...
- PostgreSQL Replication之第四章 设置异步复制(6)
4.6 有效的清理和恢复结束 最近几年, recovery.conf 已经变得越来越强大了.早在初期(在 PostgreSQL 9.0之前), 仅有 restore_command 和一些 recov ...
- PostgreSQL Replication之第四章 设置异步复制(2)
4.2 配置级联复制 正如您在本章已经看到的,设置流复制真的很容易.只需要设置几个参数,做一个基础备份,并享受您的复制设置. 在许多情况下,这种情况更有一点点微妙.在这个例子中我们假设:我们要使用一个 ...