题意:
给出p<=105个二元组(vi,fi),其中vi表示数值大小,fi表示有几个
每个数值x[jk]的贡献度计算方法为:
最长的满足x[j1]<=x[j2]<=…<=x[jk]>=x[jk+1]>=…>=x[jm−1]>=x[jm]的序列的长度(类似于开口向下的抛物线)
求最大贡献度和(ULL)以及得到最大贡献度和的序列个数(mod 109+7)
分析:
观察发现只要是单峰的序列就满足贡献度和最大,证明用简单的反证法就可以了
问题接下来如何求解个数,先对二元组排序
我们可把问题转化为峰放在哪里产生的贡献度
接下来我们发现最大的(峰)只能放在次大的附近,并且不可拆分
那么我们将最大的看成整体往次大的中插入,一共有fcur+1个插入位置
同理接下来,我们将最大的和次大的“打包”作为新的“最大”的整体往剩余次大的中插入,一共有fnxt+1个插入位置
那么cnt=(fn−1+1)∗(fn−1+1)∗⋯∗(f1+1)
代码:
//
// Created by TaoSama on 2015-12-08
// Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
typedef unsigned long long ULL;
typedef pair<ULL, ULL> P;
int n;
P a[N];
ULL s[N];
int main() {
#ifdef LOCAL
freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
int t; scanf("%d", &t);
int kase = 0;
while(t--) {
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%llu%llu", &a[i].first, &a[i].second);
sort(a + 1, a + 1 + n);
ULL sum = 0;
for(int i = 1; i <= n; ++i) {
s[i] = s[i - 1] + a[i].second;
sum += s[i] * a[i].second;
}
ULL cnt = 1;
for(int i = n - 1; i; --i) cnt = cnt * (a[i].second + 1) % MOD;
printf("Case %d: %llu %llu\n", ++kase, sum, cnt);
}
return 0;
}