UVALive 6926Maximum Score(组合数学)
来源:互联网 发布:呜呼与嗟乎的意思 编辑:程序博客网 时间:2024/06/05 21:51
题意:
给出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 << endlconst 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;}
0 0
- UVALive 6926Maximum Score(组合数学)
- UVALive 6653 Pattern Locker(组合数学)
- UVALive 3720 Highways 组合数学
- UVALive 6844 Combination(组合数学)
- hdoj Score 2534 (数学)
- UVaLIve 2889 | LA 2889 | UVa 12050 - Palindrome Numbers (组合数学)
- UVALive 7040 Color (容斥原理 + 组合数学递推公式 + 求逆元 + 基础数论)
- UVALive 7040 Color (容斥原理 + 组合数学递推公式 + 求逆元 + 基础数论)
- UVALive 6618 Skycity(数学)
- UVALive 6469 Deranged Exams 组合数学+容斥原理
- Codeforces Round #445 Div1 C:Maximum Element (组合数学+DP)
- HDOJ 2534 Score(数学)
- HDOJ2045(组合数学)
- Combinations(组合数学)
- *UVALive 6657 - GCD XOR(数学)
- 【UVALive】2145 - Lost in Space(数学)
- UVAlive 2911 Maximum(贪心)
- UVALive - 2911 Maximum
- 09 多态
- 10 包装类(NSValue和NSNumber)
- 11 类别(category)和扩展(extension)
- 12 协议
- 13 异常
- UVALive 6926Maximum Score(组合数学)
- 14 反射
- 15 手动内存管理
- 16 Foudation框架之NSString和NSMutableString
- 17 Foundation框架之NSDate、NSDateFormatter、NSDateComponents、NSCalendar、NSLocale、NSTimer
- 18 对象的copy与mutableCopy方法
- 19 NSCopying与NSMutableCopying协议+深复制和浅复制
- Java --- 就业指导
- Github的使用