对于每个元素,最理想的情况就是都在它的左边或者右边,那么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. Servlet拦截匹配规则可以自已定义,拦截哪种URL合适?

    Servlet拦截匹配规则可以自已定义,拦截哪种URL合适? 当映射为@RequestMapping("/user/add")时,为例: 1.拦截*.do.*.htm, 例如:/u ...

  2. SqlServer2012——多表连接查询

    1.基本连接 select A.姓名,A.性别,B.班级名,B.家庭住址 From 学生信息 A,班级信息 B where A.所属班级=B.班级编号 --把A表与B表连接起来 2.内连接 --内连接 ...

  3. iscsi使用教程

    服务端 服务器环境 已经安装过qemu-img的32位ubuntu $ uname -a Linux ubuntu-virtual-machine 3.13.0-46-generic #76-Ubun ...

  4. 云服务器、虚拟主机和VPS的区别

    虚拟主机就是利用网络空间技术,把一台服务器分成许多的"虚拟"的主机,每一台网络空间都具有独立的域名和IP地址,具有完整的Internet服务器功能.网络空间之间完全独立,在外界看来 ...

  5. js的Element.scrollIntoView的学习

    1.Element.scrollIntoView()    该方法让当前元素滚动到浏览器窗口的可是区域内: 2.语法: element.scrollIntoView();//等同于element.sc ...

  6. 内置对象(Math对象、Date对象、Array对象、String对象)常用属性和方法

    Math对象 Math 是一个内置对象, 它具有数学常数和函数的属性和方法.不是一个函数对象. 与其它全局对象不同的是, Math 不是一个构造函数.  Math 的所有属性和方法都是静态的. 跟数学 ...

  7. 源码分析(一) 进程cleos的命令解析

    EOS版本:4.0   一.进程cleos的作用   cleos,即为client eos.从名字就可以猜出来,它是一个标准的客户端程序,而实际上,它也确实为一个标准的client^_^   准确地说 ...

  8. Codeforces 1167E(思路、数据处理)

    思路 不难想到枚举\(l\),那如何高效求出最小的\(r\)?这样答案加上\(x-r+1\)即可. 如果\(l\)并没在序列里出现--没啥想法:如果\(l\)是序列里的数,我们可以做的事情是记下每个数 ...

  9. 丝滑顺畅:使用CSS3获取60FPS动画

    原文链接: Smooth as Butter: Achieving 60 FPS Animations with CSS3 在移动端使用动画元素是很容易的. 如果你能遵循我们的这里的提示, 在移动端适 ...

  10. JS代码运行延迟

    还是上篇文章的项目. 现在是屏幕上需要显示九张图表,刚好用一张3X3的表格来显示.但是负责这块内容的同事始终没法让九张图表同时显示,有些图表的位置空了出来. 大家百思不得其解,最后只得求助技术经理. ...