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 ...
随机推荐
- Linux硬链接和软链接的差别
1.硬链接文件和原文件指向相同的数据,两者就像克隆一样,inode号也相同,当删除原 文件时. 硬链接文件仍然存在有效. 但硬链接文件不同于文件的复制.应该说硬链接文件的产生仅仅是原文件所 在文件夹文 ...
- Visual Assist X 10.8.2036的Crack破解补丁.2014.05.22 (General release.)
说起来,VA公布上一个Genreal Release版本号已经是过春节那阵子时候的事了,时间过得真快. VA小组又给我们带来了新版本号的Visual Assist编码助手的 2036 版本号, 这个版 ...
- new,malloc,GlobalAlloc具体解释
WINDOWS下最好的方式是用VirtualAlloc分配内存,他不是在堆,也不是栈,而是直接在进程的地址空间中保留一快内存.尽管用起来最不方便. 可是速度快,也最灵活 new,malloc,Glob ...
- CG 内置函数 和 HLSL 内置函数
CG 内置函数 英伟达官网链接: http://http.developer.nvidia.com/Cg/index_stdlib.html absacosallanyasinatan2atanbi ...
- 32.AngularJS 表达式
转自:https://www.cnblogs.com/best/tag/Angular/ AngularJS 表达式写在双大括号内:{{ expression }}. AngularJS 表达式把数据 ...
- BZOJ 球形空间产生器 解题报告(高斯消元)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1013 1013: [JSOI2008]球形空间产生器sphere 有一个球形空间产生器能 ...
- 【深入篇】自定义ExpandableListView,实现二级列表效果
先看效果图: 上图是我们要实现的效果,那么现在我们开始着手去做,主要分为以下几步: 一丶我们需要根据效果图去思考该如何动手,从上图分析看,我们可以用一个相对布局RelativeLayout来完成gro ...
- 关于iOS适配问题
大家都知道在iOS开发当中对于UI适配问题可以从如下两个方面去考虑: 1.比例适配 2.利用autolayout自动布局 通常情况来说,利用auto自动布局是一个比较好的方案,开发者可以利用story ...
- github下载速度慢解决方法
1.获取 global.ssl.fastly地址 访问 http://github.global.ssl.fastly.net.ipaddress.com/#ipinfo 获取cdn域名以及ip地址 ...
- vue 父子组件传值:props和$emit
<!--子组件页面--> <template> <div class="hello"> <!-- 添加一个input输入框 添加keypr ...