BestCoder Round #63(Div.2) (4/4) (Div.1) (3/4)

maksyuki 发表于 比赛 分类,标签:
0

A sequence1

Problem Description

Given an array a with length n, could you tell me how many pairs (i,j) ( i < j ) for abs(ai−aj) mod b=c.

Input

Several test cases(about 5)

For each cases, first come 3 integers, n,b,c(1≤n≤100,0≤c<b≤109)

Then follows n integers ai(0≤ai≤109)

Output

For each cases, please output an integer in a line as the answer.

Sample Input

3 3 2
1 2 3
3 3 1
1 2 3

Sample Output

1

2

Source

BestCoder Round #63 (div.2)

 

题目类型:枚举

算法分析:直接双重枚举+判断即可

 

B sequence2

Problem Description

Given an integer array bi with a length of n, please tell me how many exactly different increasing subsequences. P.S. A subsequence bai(1≤i≤k) is an increasing subsequence of sequence bi(1≤i≤n) if and only if 1≤a1<a2<...<ak≤n and ba1<ba2<...<bak.
Two sequences ai and bi is exactly different if and only if there exist at least one i and ai≠bi.

Input

Several test cases(about 5)

For each cases, first come 2 integers, n,k(1≤n≤100,1≤k≤n)

Then follows n integers ai(0≤ai≤109)

Output

For each cases, please output an integer in a line as the answer.

Sample Input

3 1
1 2 2
3 2
1 2 3

Sample Output

2

3

Source

BestCoder Round #63 (div.2)

 

题目类型:二维dp

算法分析:dp[i][j]表示长度为i且最后一个数字为j所构成的不同子序列个数,状态转移方程为dp[i][j] = Sigma dp[i-1][k](1 <= k <= j - 1且ak < aj)。注意看清题目!!!注意要使用高精度求解!!!

 

C matrix

Problem Description

Given a matrix with n rows and m columns ( n+m is an odd number ), at first , you begin with the number at top-left corner (1,1) and you want to go to the number at bottom-right corner (n,m). And you must go right or go down every steps. Let the numbers you go through become an array a1,a2,...,a2k. The cost is a1∗a2+a3∗a4+...+a2k−1∗a2k. What is the minimum of the cost?

Input

Several test cases(about 5)

For each cases, first come 2 integers, n,m(1≤n≤1000,1≤m≤1000)

N+m is an odd number.

Then follows n lines with m numbers ai,j(1≤ai≤100)

Output

For each cases, please output an integer in a line as the answer.

Sample Input

2 3
1 2 3
2 2 1
2 3
2 2 1
1 2 4

Sample Output

4

8

Source

BestCoder Round #63 (div.2)

 

题目类型:二维线性dp

算法分析:dp[i][j]表示到(i, j)位置所具有的最小花费。若i + j为偶数,则dp[i][j] = min(dp[i-1][j], dp[i][j-1])。若i + j为奇数,则dp[i][j] = min(dp[i-1][j] + aa[i-1][j] * aa[i][j], dp[i][j-1] + aa[i][j-1] * aa[i][j])

 

 

D balls

Problem Description

There are n balls with m colors. The possibility of that the color of the i-th ball is color j is ai,jai,1+ai,2+...+ai,m. If the number of balls with the j-th is x, then you should pay x2 as the cost. Please calculate the expectation of the cost.

Input

Several test cases(about 5)

For each cases, first come 2 integers, n,m(1≤n≤1000,1≤m≤1000)

Then follows n lines with m numbers ai,j(1≤ai≤100)

Output

For each cases, please output the answer with two decimal places.

Sample Input

2 2
1 1
3 5

2 2
4 5
4 2

2 2
2 4
1 4

Sample Output

3.00

2.96

3.20

Source

BestCoder Round #63 (div.2)

 

题目类型:概率期望

算法分析:大致的思路是根据概率期望的线性可加性,将每种情况分开考虑。一个非常重要的一点是:将具有第i种颜色小球个数v和具有第i种颜色的小球(可重复)的对数之间建立了一一对应的关系,详细解法可以参考:

http://blog.csdn.net/snowy_smile/article/details/50032485#comments