对于每个元素,最理想的情况就是都在它的左边或者右边,那么sort一下就可以得到一个特解了,然后大的中间不能有小的元素,因为如果有的话,那么无论选小的还是选大的都不是最优。对小的元素来说,比它大的元素在哪里是没有关系的。所以把大的看作一个整体,然后插空法算出总方案数。

答案用llu存

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; typedef unsigned long long ull;
const int mod = ;
const int maxp = 1e5+;
struct Unit
{
int v;
ull f;
bool operator < (const Unit&rhs) const{
return v<rhs.v;
}
}num[maxp];
ull sum[maxp]; int main()
{ int T;
scanf("%d",&T);
int cas = ;
ull ans1,ans2;
while(T--){
int p;
scanf("%d",&p); for(int i = ; i < p; i++){
scanf("%d%llu",&num[i].v,&num[i].f);
}
sort(num,num+p);
sum[] = num[].f;
ans1 = ; ans2 = ;
for(int i = ; i < p; i++){
sum[i] = sum[i-] + num[i].f;
}
for(int i = ; i < p;i++){
ans1 = (ans1 + num[i].f*sum[i]);
}
for(int i = ,sz = p-; i < sz; i++){
ans2 = (ans2*(num[i].f+))%mod; }
printf("Case %d: %llu %llu\n",++cas,ans1,ans2);
}
return ;
}

UVA12906 Maximum Score (组合)的更多相关文章

  1. UVA 12906 Maximum Score 排列组合

    Maximum Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vie ...

  2. 【leetcode】1255. Maximum Score Words Formed by Letters

    题目如下: Given a list of words, list of  single letters (might be repeating) and score of every charact ...

  3. LeetCode 1255 得分最高的单词集合 Maximum Score Words Formed by Letters

    地址 https://leetcode-cn.com/problems/maximum-score-words-formed-by-letters/ 题目描述你将会得到一份单词表 words,一个字母 ...

  4. E. Little Pony and Expected Maximum(组合期望)

    题目描述: Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megaby ...

  5. [Swift]LeetCode1014. 最佳观光组合 | Best Sightseeing Pair

    Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and t ...

  6. LeetCode 1102. Path With Maximum Minimum Value

    原题链接在这里:https://leetcode.com/problems/path-with-maximum-minimum-value/ 题目: Given a matrix of integer ...

  7. 【LeetCode】1102. Path With Maximum Minimum Value 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+并查集 优先级队列 日期 题目地址:https: ...

  8. 【LeetCode】1021. Best Sightseeing Pair 最佳观光组合(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  9. leetcode bugfree note

    463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...

随机推荐

  1. CentOS快速搭建LAMP环境

    LAMP --  Linux Apache MySQL PHP 在CentOS安装的顺序,我一般是Apache -> MySQL -> PHP 第一步.安装并配置Apache 1.使用yu ...

  2. iOS内购流程二(添加产品、沙盒账号以及上架流程)

    注意:使用了IAP的App必须先配置好协议.税务和银行业务 一.创建一个App应用 1.登录iTunes Store,点击我的App 2.新建一个App(如果App已经创建,直接点击App进入就行了) ...

  3. Python:通过一个小案例深入理解IO多路复用

    通过一个小案例深入理解IO多路复用 假如我们现在有这样一个普通的需求,写一个简单的爬虫来爬取校花网的主页 import requests import time start = time.time() ...

  4. codevs1251 括号

    1251 括号  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold       题目描述 Description 计算乘法时,我们可以添加括号,来改变相乘的顺序,比 ...

  5. To the max(求最大子矩阵和)

    To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 47985   Accepted: 25387 Desc ...

  6. 剑指Offer的学习笔记(C#篇)-- 从上往下打印二叉树

    题目描述 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 一 . 题目解析 了解过二叉树就应该知道,二叉树存在三种遍历方法:前序遍历(根→左→右).中序遍历(左→根→右).后续遍历(左→右→根 ...

  7. PKUSC 2018 题解

    PKUSC 2018 题解 Day 1 T1 真实排名 Link Solution 考虑对于每一个人单独算 每一个人有两种情况,翻倍和不翻倍,他的名次不变等价于大于等于他的人数不变 设当前考虑的人的成 ...

  8. ruby 数组 Hash相互转换

    由[索引, 值, ...] 型的数组变为哈希表 ary = [1,"a", 2,"b", 3,"c"] p Hash[*ary] # =&g ...

  9. 小G的城堡

    B 小 G 的城堡文件名 输入文件 输出文件 时间限制 空间限制castle.pas/c/cpp castle.in castle.out 1s 128MB题目描述小 G 家有一座城堡.城堡里面有 n ...

  10. java Integer判等的大坑

    在-128 至 127 范围内的赋值,Integer 对象是在IntegerCache.cache 产生,会复用已有对象,这个区间内的 Integer 值可以直接使用==进行 判断,但是这个区间之外的 ...