UVALive 6926 Maximum Score(组合数学)
2015-12-08 04:09
302 查看
题意:
给出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)
代码:
给出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 ; ULL s ; 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; }
相关文章推荐
- 初学ACM - 组合数学基础题目PKU 1833
- 【组合数学】卡塔兰数
- 卡特兰数(Catalan)及应用
- POJ1833-排列
- 1139: 出栈序列统计
- POJ 3292.Semi-prime H-numbers
- Java 产生随机的一组排列
- Catalan数
- poj_1942
- poj_1850
- HDU 4832 Chess (动态规划+组合数学)
- hdoj_2049 不容易系列之(4)——考新郎
- hdoj_2048 神、上帝以及老天爷
- hdoj_2047 阿牛的EOF牛肉串
- hdoj_2046 骨牌铺方格
- hdoj_2045 不容易系列之(3)—— LELE的RPG难题
- hdoj_2044 一只小蜜蜂...
- hdoj_2042 不容易系列之二
- hdoj_2041 超级楼梯
- zoj_2836 Number Puzzle