Maximum Score

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83008#problem/J

Description

Ron likes to play with integers. Recently he is interested in a game where some integers are given and he is allowed to permute them. His point will be calculated from the permutation made by him. Ron knows that he will get as many candies as his point, so he wants to permute the numbers to maximize his point.
Say, Ron has got n integers {x1, x2, . . . , xn} and (xi1, xi2, . . . , xin) is the permutation made by him. His point will be the sum of the score of all integers. The score of an individual number xiw in that permutation is calculated by the length of the longest subsequence (Let us consider xj1, xj2, …, xjm as the subsequence where 1 ≤ j1 < j2 < . . . < jm ≤ n) you can form with the following constraints:
1. There exists an integer k such that 1 ≤ k ≤ m and jk = iw.
2. xj1 ≤ xj2 ≤ . . . ≤ xjk−1 ≤ xjk ≥ xjk+1 ≥ . . . ≥ xjm−1 ≥ xjm.
Therefore, the score of xiw in that permutation will be m. Say, (1, 4, 3) is a permutation made by Ron using the numbers {1, 3, 4}. For this permutation, score of 1 is 1 with subsequence (1), score of 4 is 3 with subsequence (1, 4, 3) and score of 3 is 2 with subsequence (1, 3). So, Ron’s point is 6 for this permutation.
Ron is not sure how to achieve the maximum point and he is also wondering about the number of different permutations which generate that maximum value of point. You need to help Ron to calculate these two values. A permutation (x1, x2, . . . , xn) is different from another permutation (y1, y2, . . . , yn) if there exists an integer i such that 1 ≤ i ≤ n and xi is not equal to yi
.

Input

The first line of input contains a single integer T (1 ≤ T ≤ 200), which denotes the number of test cases to follow. For each test case, there will be two lines of input. The first line contains a single integer, p (1 ≤ p ≤ 105 ). The second line contains p pairs of integers. In each pair, there are two integers vi and fi (1 ≤ vi , fi ≤ 105 ) which indicate that the value vi is present fi times among the given numbers.
Therefore, f1 + f2 + . . . + fp = n, where n is the total number of integers given to Ron. All the values of vi will be distinct.

Output

For each case, in a separate line, print the case number and the maximum sum of scores and the number of permutations to achieve that sum of scores. As the number of permutations can be quite large, print it modulo 1000000007 (109 + 7). Follow Sample Input and Output for details. The value of the maximum sum of scores will fit in 64-bit unsigned integer.

Sample Input

2
2
121 1 22 1
2
71 2 35 1

Sample Output

Case 1: 3 2
Case 2: 7 2

HINT

题意

一个数的分数的定义,就是以这个点能够往左右延生多长,不一定要连续!

题解:

第一问很简单,随便想想就出来了

第二问比较麻烦,首先我们先把最小的扔在那儿,然后我们插空法就吼了,注意,最大的数一定得挨在一起,掌握这个观点就好了

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** pair<ll,ll> P[maxn];
int main()
{
//test;
int t;
cin>>t;
for(int cas=;cas<=t;cas++)
{
memset(P,,sizeof(P));
int p=read();
for(int i=;i<p;i++)
cin>>P[i].first>>P[i].second;
sort(P,P+p);
unsigned long long ans=,ans2=;
unsigned long long sum=;
for(int i=;i<p;i++)
{
sum+=P[i].second;
if(i!=p-)
{
ans2=(ans2*(P[i].second+));
if(ans2>mod)
ans2%=mod;
}
ans+=P[i].second*sum;
}
printf("Case %d: %llu %llu\n",cas,ans,ans2%mod);
}
}

UVA 12906 Maximum Score 排列组合的更多相关文章

  1. 【CodeForces】889 C. Maximum Element 排列组合+动态规划

    [题目]C. Maximum Element [题意]给定n和k,定义一个排列是好的当且仅当存在一个位置i,满足对于所有的j=[1,i-1]&&[i+1,i+k]有a[i]>a[ ...

  2. UVA12906 Maximum Score (组合)

    对于每个元素,最理想的情况就是都在它的左边或者右边,那么sort一下就可以得到一个特解了,然后大的中间不能有小的元素,因为如果有的话,那么无论选小的还是选大的都不是最优.对小的元素来说,比它大的元素在 ...

  3. UVa 11538 Chess Queen (排列组合计数)

    题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种. 析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是 ...

  4. UVa Problem 10132 File Fragmentation (文件还原) 排列组合+暴力

    题目说每个相同文件(01串)都被撕裂成两部分,要求拼凑成原来的样子,如果有多种可能输出一种. 我标题写着排列组合,其实不是什么高深的数学题,只要把最长的那几个和最短的那几个凑一起,然后去用其他几个验证 ...

  5. UVa 12712 && UVaLive 6653 Pattern Locker (排列组合)

    题意:给定 一个n * n 的宫格,就是图案解锁,然后问你在区间 [l, r] 内的所有的个数进行组合,有多少种. 析:本来以为是数位DP,后来仔细一想是排列组合,因为怎么组合都行,不用考虑实际要考虑 ...

  6. HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)

    Machine scheduling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)

    题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...

  8. 【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 ...

  9. 学习sql中的排列组合,在园子里搜着看于是。。。

    学习sql中的排列组合,在园子里搜着看,看到篇文章,于是自己(新手)用了最最原始的sql去写出来: --需求----B, C, F, M and S住在一座房子的不同楼层.--B 不住顶层.C 不住底 ...

随机推荐

  1. selenium python (十五)控制滚动条操作

    #!/usr/bin/python# -*- coding: utf-8 -*-__author__ = 'zuoanvip' #一般用到操作滚动条的两个场景    #注册时的法律条文的阅读,判断用户 ...

  2. Yii笔记---redirect重定向

    Yii的redirect方法在CControler与CHttpRequest之中都有被定义,CController中的redirect调用了CHttpRequest中的redirect方法.我们平常调 ...

  3. layout相关

    大致看了看布局大致有5种(approximately) 1. LinearLayout 2. RelativeLayout 3. FrameLayout 4. TableLayout 5. GridL ...

  4. 数往知来 三层架构 <十四>

    三层架构_1 一.三层 就是把程序的各个部分都分离,尽量的底耦合,做到分工明确.责任明确 第一层:Dal   数据访问层 第二层 :Bll  业务逻辑判断层 第三层: UI   界面显示层 比如说数据 ...

  5. Objective-C开发图书推荐

    日本Objective-C圣经级教材:Objective-C编程全解(第3版) 作      者 [日] 荻原刚志 著:唐璐,翟俊杰 译 出 版 社 人民邮电出版社 出版时间 2015-01-01 版 ...

  6. 怎样下载完整的Spring包

    自从3.2版本以后,Spring不再提供包含所有库的文件下载了只有Sping自身的最基本库,所依赖的东西需要自己搞定首先, 这个链接 包含了Spring自身和所用到的所有东西   这个 是上述链接的说 ...

  7. github上所有项目的受欢迎程度排名,包括超大型项目

    直接打开如下网址: https://github.com/search?l=Java&q=+stars%3A%3E0&ref=searchresults&type=Reposi ...

  8. 数据库中使用 Synonym和openquery

    如果,你想在一台数据库服务器上,查询另一个台数据服务器的数据该如何做呢?如果,你想在同一台数据服务器上,在不同的数据库之间查询数据,又该怎么办呢?那就让我为你介绍Synonym和openquery吧. ...

  9. 利用AuthorizeAttribute属性简单避免 MVC 中的跨域攻击

    跨域攻击---自然来路页面和目标页面不在同一个域下,所以直接判断来路域和当前自己的域就可以了. 可以广泛应用于表单提交,ajax调用或者某些不想让用户直接输入网址看到的页面 [csharp] view ...

  10. pthread_cond_wait 信号量丢失

    服务器在使用pthread_cond_wait的时候遇到一个问题.具体描述如下 一个主进程,给n个从线程发送计算请求,主进程会等待n个线程返回,在执行下一步 从线程计算完毕后,最后一个线程会通知主线程 ...