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总的的边数减去重叠的 ...
随机推荐
- Centos7.2 下安装配置pip
一.pip下载 wget https://files.pythonhosted.org/packages/ae/e8/2340d46ecadb1692a1e455f13f75e596d4eab3d11 ...
- POJ - 2955 Brackets括号匹配(区间dp)
Brackets We give the following inductive definition of a “regular brackets” sequence: the empty sequ ...
- Deep Learning - Install the Development Environment
WLS(Windows Subsystem for Linux) Base WLS Installation Guide Initializing a newly installed distro W ...
- ]Linq to EF 增删改查
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- JAVA获取本周 本月 本年 第一天和最后一天
/** * 日期工具类 */ public class DateUtils { /** * 获取今天 * @return String * */ public static String getTod ...
- JavaScript 检验变量
创建: 2019/02/20 迁入: 删除[WIP]标签(因为随时更新, 不存在完成不完成) 从[JavaScript 式与运算符]迁入typeof 更新: 2019/03/25 补充静态变量与参 ...
- 萌新笔记之Nim取石子游戏
以下笔记摘自计算机丛书组合数学,机械工业出版社. Nim取石子游戏 Nim(来自德语Nimm!,意为拿取)取石子游戏. 前言: 哇咔咔,让我们来追寻娱乐数学的组合数学起源! 游戏内容: 有两个玩家面对 ...
- TensorFlow中设置学习率的方式
目录 1. 指数衰减 2. 分段常数衰减 3. 自然指数衰减 4. 多项式衰减 5. 倒数衰减 6. 余弦衰减 6.1 标准余弦衰减 6.2 重启余弦衰减 6.3 线性余弦噪声 6.4 噪声余弦衰减 ...
- 获取URL地址栏参数(正则表达式)
]] = isEncode ? decodeURIComponent(arg[2]) : arg[2]; }); return obj;}
- 重启centOS丢失nginx.pid导致无法启动nginx的解决方法
目录 找到nginx 找到nginx的配置文件 拼接命令,启动nginx Nginx指令拓展知识(中英对照): tags: centOS linux nginx categories: 服务器 找到n ...