解题思路:给你p个数,和每个数的个数,问你怎么安排使得每个位置上的最长单峰子序列的和最长。
解题思路:显然按顺序方是最大的。
解题代码:
1 // File Name: j.cpp 2 // Author: darkdream 3 // Created Time: 2015年04月04日 星期六 15时35分41秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<stack> 11 #include<bitset> 12 #include<algorithm> 13 #include<functional> 14 #include<numeric> 15 #include<utility> 16 #include<sstream> 17 #include<iostream> 18 #include<iomanip> 19 #include<cstdio> 20 #include<cmath> 21 #include<cstdlib> 22 #include<cstring> 23 #include<ctime> 24 #define LL long long 25 #define M 1000000007 26 #define maxn 100005 27 using namespace std; 28 int t ; 29 int n; 30 struct node{ 31 unsigned LL val ,num; 32 }a[maxn]; 33 unsigned LL ans ,ansnum; 34 bool cmp(node a, node b) 35 { 36 return a.val < b.val; 37 } 38 int main(){ 39 // freopen("input","r",stdin); 40 // freopen("output","w",stdout); 41 42 scanf("%d",&t); 43 for(int CA = 1;CA <= t ; CA++) 44 { 45 scanf("%d",&n); 46 for(int i =1 ;i <= n ;i ++) 47 { 48 scanf("%llu %llu",&a[i].val,&a[i].num); 49 } 50 sort(a+1,a+1+n,cmp); 51 unsigned LL tsum =0 ; 52 ans = 0 ; 53 ansnum = 1; 54 for(int i = 1;i <= n;i ++) 55 { 56 tsum += a[i].num; 57 ans = (ans + a[i].num * tsum); 58 if(i != 1) 59 ansnum = ansnum *(a[n-i+1].num+1) % M; 60 } 61 printf("Case %d: %llu %llu\n",CA,ans,ansnum); 62 } 63 64 return 0; 65 }
没有梦想,何谈远方