您的位置:首页 > 其它

hdu----Lotus and Characters

2017-05-19 16:18 351 查看
问题描述
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$种字母的价值和个数限制。

输出描述
对于每组数据,输出一行一个整数,表示答案。

输入样例
2
2
5 1
6 2
3
-5 3
2 1
1 1

输出样例
35
5


就是个累加的问题,思维技巧题
#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。
 

[align=left]Inpu[/align]
First line is T(0≤T≤1000)
denoting the number of test cases.

For each test case,first line is an integer n(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.

 

[align=left]Output[/align]
For each test case.output one line containing a single integer,denoting the answer.

 

[align=left]Sample Input[/align]

2
2
5 1
6 2
3
-5 3
2 1
1 1
 
[align=left]Sample Output[/align]

35
5
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: