对于每个元素,最理想的情况就是都在它的左边或者右边,那么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. SQL中的drop,truncate和delete的区别

    (1)   DELETE语句执行删除的过程是每次从表中删除一行,并且同时将该行的删除操作作为事务记录在日志中保存以便进行进行回滚操作.TRUNCATE TABLE 则一次性地从表中删除所有的数据并不把 ...

  2. JAVA企业级开发-BOM&DOM(03)

    一.BOM对象介绍 BOM对象:Browser Object Model 浏览器对象模型.把整个浏览器当做一个对象来处理. 一个浏览器对象中又包含了其他的对象. 重点介绍:window.history ...

  3. tyvj4868 天天和不可描述

    描述

  4. js的Element.scrollIntoView的学习

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

  5. 进击JavaScript核心 --- (1)基本数据类型

    ES5之前提供了 5种基本数据类型 和 1种引用数据类型 基本数据类型:Undefined, Null, String, Number, Boolean 引用数据类型:Object ES6开始引入了一 ...

  6. 2017swpu-ctf总结

    2017swpu-ctf总结 今年是我第一次出题感受很多,就分析几道我印象最深刻的题吧 你能进入后台吗? 这道题主要是考察php_screw还有md5加密开启true过后的注入 phpscrew加密在 ...

  7. net core分块上传文件

    net core分块上传文件   写完asp.net多文件上传(http://www.cnblogs.com/bestckk/p/5987383.html)后,感觉这种上传还是有很多缺陷,于是...( ...

  8. GPIO的翻转操作方法

    STM32在进行IO翻转操作的时候可以使用以下方法:以PE.5为例 GPIO_WriteBit(GPIOE,GPIO_Pin_5,(BitAction)(1-(GPIO_ReadOutputDataB ...

  9. D. Edges in MST 图论

    http://codeforces.com/contest/160/problem/D base on 克鲁斯卡尔, 首先每次都是对权值相同的边进行统一处理,假如加入了当前这条边出现了回路,那就能确定 ...

  10. (转)useradd用户,组管理案例

    原文:https://www.cnblogs.com/Csir/p/6403830.html?utm_source=itdadao&utm_medium=referral 示例:要求oldbo ...