UVA12906 Maximum Score (组合)
对于每个元素,最理想的情况就是都在它的左边或者右边,那么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 (组合)的更多相关文章
- UVA 12906 Maximum Score 排列组合
Maximum Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vie ...
- 【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 ...
- LeetCode 1255 得分最高的单词集合 Maximum Score Words Formed by Letters
地址 https://leetcode-cn.com/problems/maximum-score-words-formed-by-letters/ 题目描述你将会得到一份单词表 words,一个字母 ...
- E. Little Pony and Expected Maximum(组合期望)
题目描述: Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megaby ...
- [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 ...
- LeetCode 1102. Path With Maximum Minimum Value
原题链接在这里:https://leetcode.com/problems/path-with-maximum-minimum-value/ 题目: Given a matrix of integer ...
- 【LeetCode】1102. Path With Maximum Minimum Value 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+并查集 优先级队列 日期 题目地址:https: ...
- 【LeetCode】1021. Best Sightseeing Pair 最佳观光组合(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- leetcode bugfree note
463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...
随机推荐
- php array数组(第一部分)
创建一个数组 <?php $arr = array("My","name","is","zhangsan"); e ...
- 交互原型设计软件axure rp学习之路(三)
(三)Axure rp元件的触发事件 l OnClick(点击时): 鼠标点击事件,除了动态面板的所有的其他元件的点击时触发.比如点击按钮. l OnMouseEnter(鼠标移入时): 鼠标进入 ...
- HighChar
chart: { type:'bar', borderWidth:2, borderColor: '#CA5100', backgroundColor: '#90ED7D', shadow: { // ...
- 数据库路由中间件MyCat - 源代码篇(3)
此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 2. 前端连接建立与认证 Title:MySql连接建立以及认证过程client->MySql:1.T ...
- python寻找小于给定值的最大质数
# -*- utf-8 -*- # @Time: 2019-04-16 # @ Author: chen def prime(self, value): """判断是否为 ...
- 洛谷P3272 [SCOI2011]地板(插头dp)
传送门 感谢大佬的教导->这里 容易注意到,本题的合法路径“L型地板”有一些特殊的地方:拐弯且仅拐弯一次. 这由于一条路径只有两种状态:拐弯过和没拐弯过,因此我们可以尝试着这样定义新的插头: 我 ...
- python3编程技巧二——如何在列表、字典、集合 中根据条件筛选数据
一.列表筛选数据 # coding=utf-8 from random import randint # 创建随机列表 l = [randint(-10, 10) for i in range(10) ...
- 关于Struts漏洞工具的使用
最新struts-scan资源: https://www.cesafe.com/3486.html 一,将资源下载后,放入liunx系统中,并且需要具备python2的操作环境 二,打开终端使用如下命 ...
- Vuex+axios
Vuex+axios Vuex简介 vuex是一个专门为Vue.js设计的集中式状态管理架构. 状态? 我们把它理解为在data中需要共享给其他组件使用的部分. Vuex和单纯的全局对象有以下不同 ...
- php:封装了个时间函数,返回类似“1分钟前发布”,“5小时前发布”,“3年前发布”
处理和时间有关的时候,像发布问题等通常不会用date格式的时间,而是用类似"3分钟前发布"等格式,下面封装的php函数就可以使用: 注意:当有用到strtotime()函数的记得加 ...