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. OPENGL学习笔记整理(五):着色语言

    有些事情本身就是十分奇怪的.在传统上,图形硬件的设计目的是用于快速执行相同的硬编译指令集.不同的计算步骤可以被跳过,参数可以被调整,但计算本身确实固定不变的.然而,随着技术的发展,却越来越变得可以编程 ...

  2. Asp.net MVC4 使用EF实现数据库的增删改查

    EF的使用 步骤: (1)将EF添加到项目:在Model右击添加新建项 找到ADO.NET实体数据模型,接着... (2)实现数据库的增删改查       查询 (因为在Model中已经添加EF实体了 ...

  3. 数往知来JavaScript_DOM<十>

    一.DOM   1.onclick事件 表示点击 一般用在-->跳转 a标签,希望点击的时候不去跳转,而是做别的事情,并在里面返回一个false <a href="http:// ...

  4. scala: How to write a simple HTTP GET request client in Scala (with a timeout)

    Scala CookBook: http://scalacookbook.com/ @throws(classOf[java.io.IOException]) @throws(classOf[java ...

  5. 【转】Android Intent Action 大全

    String ADD_SHORTCUT_ACTION 动作:在系统中添加一个快捷方式.. “android.intent.action.ADD_SHORTCUT” String ALL_APPS_AC ...

  6. gson在java和json串之间的应用

    public class JsonToJavaUtil { /** * 将json转成成javaBean对象 * * @param <T> * 返回类型 * @param json * 字 ...

  7. Jquery 操作页面中iframe自动跟随窗口大小变化,而页面不出现滚动条,只在iframe内部出滚动条

    很多时候大家需要iframe自适应所加载的页面高度而不要iframe滚动条,但是这次我需要的是页面不需要滚动条而iframe要滚动条,且iframe自动跟随窗口大小变化.自适应页面大小.下面是代码,下 ...

  8. var隐式类型

    var dogName = "ruiky"; 1.[编译器]会在编译时自动根据值的类型推断这个变量的类型:       2.变量类型不可更改:因为声明的时候已经确定类型了. 3.可 ...

  9. 【多线程】Java并发编程:并发容器之CopyOnWriteArrayList(转载)

    原文链接: http://ifeve.com/java-copy-on-write/ Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容 ...

  10. RedHat/CentOS6.4---永久关闭iptables

    今天无意中发现一个现象,当我关闭iptables并且停止iptables服务,但是总会有一些出奇的事情发生,当我再次启动系统,查看iptables状态,iptables又自动开启,很是无奈啊!在Red ...