博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 12906 Maximum Score 排列组合
阅读量:6798 次
发布时间:2019-06-26

本文共 3941 字,大约阅读时间需要 13 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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-9const int inf=0x3f3f3f3f;const ll infll = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//**************************************************************************************pair
P[maxn];int main(){ //test; int t; cin>>t; for(int cas=1;cas<=t;cas++) { memset(P,0,sizeof(P)); int p=read(); for(int i=0;i
>P[i].first>>P[i].second; sort(P,P+p); unsigned long long ans=0,ans2=1; unsigned long long sum=0; for(int i=0;i
mod) ans2%=mod; } ans+=P[i].second*sum; } printf("Case %d: %llu %llu\n",cas,ans,ans2%mod); }}

 

转载地址:http://faego.baihongyu.com/

你可能感兴趣的文章
BGP路由协议Q&A
查看>>
bash_profile和bashrc区别
查看>>
KVM - 快照
查看>>
【mysql基础】02、数据库基础
查看>>
JTable 使用细讲
查看>>
我的友情链接
查看>>
51、组播Multicast简介
查看>>
CentOS 安装Oracle 11G 参数配置
查看>>
[PYTHON]简单的文件增删改查处理
查看>>
mysql导出数据结构+导出数据
查看>>
我的友情链接
查看>>
对于编程:要么热爱,要么离开
查看>>
Linux常用的命令
查看>>
lvm 动态扩容
查看>>
简单工厂模式、工厂模式、抽象工厂模式的对比与应用场景(代码举例)
查看>>
python操作Excel的几种方式
查看>>
0913作业(冒泡排序、二分查找法、模拟摇乐游戏)
查看>>
【数据结构队列的应用】用队列打印杨辉三角
查看>>
Compilation failed: this version of PCRE is not compiled with PCRE_UTF8 support at offset 0
查看>>
Java—基础之extends用法详解及简单实例
查看>>