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
 

Inpu
First line is T(0T1000) denoting the number of test cases.
For each test case,first line is an integer n(1n26),followed by n lines each containing 2 integers vali,cnti(|vali|,cnti100),denoting the value and the amount of the ith character.
 

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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 人被传染了耳螨怎么办 人被传染耳螨怎么办 头发干枯毛躁怎么办做什么发型 学校不给转学籍怎么办 结婚证号码错了怎么办 继教学分1类不够怎么办 猫咪耳螨传染人怎么办 ph值低了怎么办呀 水的ph值高怎么办 宝宝起热痱子了怎么办 宝宝热的起痱子怎么办 吃了有农药的菜怎么办 水银吃到肚子里怎么办 牙齿有牙结石怎么办可以去除 刷牙牙结石掉了怎么办 痘痘留下的黑印怎么办 脸上用了激素药怎么办 激素药膏用多了怎么办 8岁儿童牙齿不齐怎么办 两个牙齿之间有缝隙怎么办 蛀牙就剩牙根了怎么办 牙龈发白像烂了怎么办 3岁宝宝牙龈肿痛怎么办 1岁宝宝牙龈肿痛怎么办 牙疼引起的发烧怎么办 2岁小儿牙龈红肿怎么办 宝宝出牙牙龈红肿怎么办 3岁宝宝牙龈红肿怎么办 1岁宝宝牙龈红肿怎么办 4岁宝宝牙龈红肿怎么办 儿童牙黑了怎么办啊 牙黑了掉了一块怎么办 1岁幼儿牙齿腐蚀怎么办 我的大牙变黑了怎么办 牙齿里面黑了疼怎么办 最里面的牙黑了怎么办 牙龈的肉裂开了怎么办 有蛀牙怎么办可以变好么 拔智齿没拔干净怎么办 蛀牙只剩牙根了怎么办 牙掉的就剩牙根怎么办