225 16 23-5 32 11 1 Sample Output355 本来以为是个签到题,后来傻傻的掉了坑,一开始考虑的负数是直接排除情况的,后来才想到负数可以占位置,让后面的正数来乘以更大的基数,就是题中1,2,3……#include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>using namespace std;int n,T;int maxvalue;struct node{ int v,c;}p[30];int cmp(node a,node b){ return b.v>a.v;}int main(){ scanf("%d",&T); while (T--) { int i,j,cnt,index,value; cnt=value=0; scanf("%d",&n); for (i=0;i<n;i++) scanf("%d%d",&p[i].v,&p[i].c); sort(p,p+n,cmp); int sum=0; for (i=n-1;i>=0;i--) { for (j=0;j<p[i].c;j++) { sum+=p[i].v; if (sum>0) value+=sum; else break; } if (j<p[i].c) break; } printf("%d/n",value); } return 0;}Problem DescriptionLotus hasn 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 。 InputFirst line isT(0≤T≤1000) denoting the number of test cases.For each test case,first line is an integern(1≤n≤26) ,followed byn lines each containing 2 integersvali,cnti(|vali|,cnti≤100) ,denoting the value and the amount of the ith character. OutputFor each test case.output one line containing a single integer,denoting the answer. Sample Input225 16 23-5 32 11 1 Sample Output355
新闻热点
疑难解答