hdu----Lotus and Characters
来源:互联网 发布:创业软件股份 编辑:程序博客网 时间:2024/05/16 07:05
问题描述
Lotus有$n$种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的串。定义串的价值为:第1位字母的价值*1+第2位字母的价值*2+第3位字母的价值*3……求Lotus能构造出的串的最大价值。(可以构造空串,因此答案肯定$\geq 0$)
输入描述
第一行是数据组数$T(0 \leq T \leq 1000)$。对于每组数据,第一行一个整数$n(1 \leq n \leq 26)$,接下来$n$行,每行2个整数$val_i,cnt_i(|val_i|,cnt_i\leq 100)$,分别表示第$i$种字母的价值和个数限制。
输出描述
对于每组数据,输出一行一个整数,表示答案。
输入样例
225 16 23-5 32 11 1
输出样例
355
就是个累加的问题,思维技巧题
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[100000];int main(){ int T,n,b,num; scanf("%d",&T); while(T--) { scanf("%d",&n); int i = 0,j; while(n--) { scanf("%d %d",&b,&num); while(num--) a[i++]=b; } sort(a,a+i); int sum = 0,ans = 0; for(j = i-1; j >= 0; j--) { sum = sum + a[j]; if(sum < 0) break; ans += sum; } printf("%d\n",ans); } return 0;}
Lotus has n kinds of characters,each kind of characters has a value and a amount.She wants to construct a string using some of these characters.Define the value of a string is:its first character's value*1+its second character's value *2+...She wants to calculate the maximum value of string she can construct.
Since it's valid to construct an empty string,the answer is always≥0 。
Since it's valid to construct an empty string,the answer is always
Inpu
First line is T(0≤T≤1000) denoting the number of test cases.
For each test case,first line is an integern(1≤n≤26) ,followed by n lines each containing 2 integers vali,cnti(|vali|,cnti≤100) ,denoting the value and the amount of the ith character.
For each test case,first line is an integer
Output
For each test case.output one line containing a single integer,denoting the answer.
Sample Input
225 16 23-5 32 11 1
Sample Output
355
阅读全文
0 0
- hdu----Lotus and Characters
- HDU 6011 Lotus and Characters
- 【HDU 6011 Lotus and Characters】
- hdu 6011 lotus and characters
- HDU 6011 Lotus and Characters
- hdu 6011 Lotus and Characters
- hdu 6011Lotus and Characters
- HDU:6011 Lotus and Characters
- hdu 6011 Lotus and Characters
- hdu 6011 Lotus and Characters
- HDU 6011 Lotus and Characters
- HDU-6011 Lotus and Characters
- Hdu 6011 Lotus and Characters【贪心+暴力】
- HDU 6011 BC 91 Lotus and Characters
- hdu 6011 Lotus and Characters 思维
- HDU 6011 Lotus and Characters【思维】【pair】
- Lotus and Characters
- Lotus and Characters
- Windows下搭建MySql Master-Master Replication
- [leetcode: Python]557. Reverse Words in a String III
- nginx-GET /favicon.ico HTTP/1.1
- 在浏览器console中使用jQuery
- 计算类型大小的宏
- hdu----Lotus and Characters
- Lua中的loadfile、dofile、require详解
- openssl 非对称加密算法RSA命令详解
- 使用CTE递归的方式实现时间维度表
- Android中Button的onClick实现方法。
- 跳台阶
- spring->aop中proxy-target-class属性的含义以及动态代理机制
- 爬虫 Filtered offsite request to XXX.com 错误.
- plsql 永久注册码适用个版本