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 ...
随机推荐
- 【C#】报表制作<机房重构>
前言 和VB须要引用其它报表软件不同,VS自带报表设计的功能,初次尝试.就感受到了它的强大之处. 报表制作 话不多说.直接报表的制作过程. 1.首先,我们要先制作一个报表的容器.放到我们显示报表的窗口 ...
- Linux系统编程——进程间通信:管道(pipe)
管道的概述 管道也叫无名管道,它是是 UNIX 系统 IPC(进程间通信) 的最古老形式,全部的 UNIX 系统都支持这样的通信机制. 无名管道有例如以下特点: 1.半双工,数据在同一时刻仅仅能在一个 ...
- 什么是MySQL?(一)
课程大纲 第一章:初识MySQL 1.1什么是MySQL? 1.2如何安装MySQL? 1.3如何配置MySQL? 1.4如何启动和关闭MySQL? 1.5MySQL的登录和退出 1.6如何 ...
- 如何设定editplus为txt默认打开程序?
如何设定editplus为txt默认打开程序? 如图操作即可:
- SSRS 报表 递归列表
SSRS 报表 递归列表 .需要数据集合中两个必备字段 ID PID 1.添加数据集合,在图上标记的地方点击右键添加数据集合,根据需求自己编写 2.点击插入选项卡 中的 矩阵 有两种方式 一种是 矩 ...
- 001.TypeScript简介.md
TypeScript是一门开源的,由微软开发维护的,发布于2012年10月的静态类型的语言: 他是ECMAScript的超集,支持JavaScript的所有语法和语义,并且在此基础之上提供了更多额外的 ...
- c# 值类型 之枚举
1声明枚举(enum)类型的变量 enum 变量名 { //标识符列表中,元素与元素之间用 , 逗号分隔: 标识符列表 } 枚举列表中的每个符号代表一个整数值,一个比他前面符号大的整数值,默认情况下, ...
- Android chromium 1
For Developers > Design Documents > Java Resources on Android Overview Chrome for Android ...
- NodeJS学习笔记 进阶 (7)express+session实现简易身份认证(ok)
个人总结: 这篇文章讲解了express框架中如何使用session,主要用了express-session这个包.更多可以参考npm.js来看,读完这篇文章需要10分钟. 摘选自网络: 文档概览 本 ...
- python 高阶函数 与关键字参数
修饰器 之前我一直有一个疑惑,就是修饰器里面对函数的操作为什么不能直接写进函数里面就好了吗?何必这么麻烦呢,当我进一步理解之后,原来修饰器的作用就是完成那些不能写进函数里面的功能的,好比必须要等到函数 ...