2019 GDUT Spring Team_up Training III(Div.1+Div.2)(DP,数位DP)

Contest Setting(DP)

A group of contest writers have written n problems and want to use k of them in an upcoming contest. Each problem has a difficulty level. A contest is valid if all of its k problems have different difficulty levels.
Compute how many distinct valid contests the contest writers can produce. Two contests are distinct if and only if there exists some problem present in one contest but not present in the other. Print the result modulo 998,244,353.

Input

The first line of input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 1000). The next line contains n space-separated integers representing the difficulty levels. The difficulty levels are between 1 and 109
(inclusive).

Output

Print the number of distinct contests possible, modulo 998,244,353.

Sample
Input

5 2
1 2 3 4 5

Output

10

Input

5 2
1 1 1 2 2

Output

6

Input

12 5
3 1 4 1 5 9 2 6 5 3 5 8

Output

316

题目大意:

给你n到题目的难度水平,让你从中选取k道题来组成一个contest,要求这k道题难度没有相同的,让你求方案数。

题目思路:

(比赛的时候也有往dp的方面去想,但无奈还是想不出来)
当然,数据的范围很广,我们要把它缩小一下,因为我们并不需要具体的难度值,我们只需要相同难度的题目的个数。
我用val数组来存放不同难度题目的数量。
dp[i][j]代表前i个数中挑出j个的方案数,那么就可以这样状态转移:
dp[i][j] = dp[i - 1][j - 1] * val[i] + dp[i - 1][j]; (选择第j个时会增加dp[i-1][j-1]*val[i]个。)
也就是前i - 1个数挑出j个的方案数(这是之前就求出来的,相当于继承了下来),dp[i - 1][j - 1] * val[i] 这个是新增加的一道题目所带来的方案书的增加量。(现在的 = 之前的 + 新增加的。)

#include <bits/stdc++.h>
using namespace std;
#define ll long long

const ll mod=998244353;
int val[1005];
ll dp[1005][1005];//代表前i个数中挑出j个的方案数
ll a[1005];

int main(){
  int n,k;
  cin>>n>>k;
  for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }
  sort(a+1,a+n+1);//将输入的题目难度排序
  int cnt=1,o=0;
  for(int i=1;i<=n;i++){
    if(a[i]==a[i-1]){
        cnt++;
    }
    else{
        val[o++]=cnt;//记录每个难度有多少道题目
        cnt=1;
    }
  }
  val[o++]=cnt;//将最后一个难度的题目数也记录一遍
  for(int i=0;i<=n;i++){
    dp[i][0]=1;
  }
  for(int i=1;i<o;i++){
       for(int j=1;j<=k;j++){
        dp[i][j]=(dp[i-1][j-1]*val[i]%mod+dp[i-1][j])%mod;
       }
  }
  /*for(int i=0;i<o;i++){
    for(int j=0;j<=k;j++){
        printf("%lld ",dp[i][j]);
        if(j==k) cout<<endl;
    }
  }*/
  cout<<dp[o-1][k]<<endl;
}

Count The Bits

Given an integer k and a number of bits b (1 ≤ b ≤ 128), calculate the total number of 1 bits in thebinary representations of multiples of k between 0 and 2b − 1 (inclusive), modulo 1,000,000,009.

Input

The input will consist of two integers k and b on a single line, with 1 ≤ k ≤ 1000 and 1 ≤ b ≤ 128.

Output

Write your result as an integer on a single line.

Sample
Input

1 4

Output

32

Input

10 5

Output

8

Input

100 7

Output

3

Input

3 28

Output

252698795

Input

11 128

Output

856188165

Input

1 26

Output

872415232

Input

876 128

Output

530649653

题目大意:

求0~2b 中所有k的倍数二进制表示1的个数,且mod 1,000,000,009.

题目思路:

数位dp:

  • dp[ i ][ j ] 表示到第i个二进制(0~(2i−1)),中模K余数为j的二进制表示1的个数
  • cnt[ i ][ j ] 表示到第i个二进制(0~(2i−1)),中模K余数为j的数的个数
状态转移:

j = (2i+pre)%K

  • dp[ i ][ j ] = dp[ i - 1 ][ j ] + dp[ i - 1 ][ pre ] + cnt[ i - 1 ][ pre ]
  • cnt[ i ][ j ] = cnt[ i - 1 ][ j ] + cnt[ i - 1 ][ pre ]
#include <bits/stdc++.h>
#define LL long long
#define maxn 1005
using namespace std;
int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 9;
LL dp[200][1003], cnt[200][1003];

int main() {
    LL k,b;
    cin>>k>>b;
        memset(cnt,0,sizeof(cnt));
        memset(dp,0,sizeof(dp));
        cnt[1][0]++;
        cnt[1][1%k]++;
        dp[1][1%k]++;
        LL tmp=1%k;
        for (int i=2;i<=b;i++) {
            tmp=tmp*2%k;
            for (int j=0;j<k;j++) {
                int pre=(j+k-tmp)%k;
                cnt[i][j]=(cnt[i-1][j]+cnt[i-1][pre])%mod;
                dp[i][j]=(dp[i-1][j]+cnt[i-1][pre]+dp[i-1][pre]%mod)%mod;
            }
        }
        cout<<dp[b][0]<<endl;
    return 0;
}

Problem F — limit 2 seconds

Rectangles

在这里插入图片描述
You are given several axis-aligned rectangles. Compute the sum of the area of the regions that are covered by an odd number of rectangles.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 105), representing the number of rectangles. Each of the next n lines contains four space-separated integers x1, y1, x2, and y2, each between 0 and 109, describing the coordinates of a rectangle.

Output

Print, on one line, the total area covered by an odd number of rectangles as an exact integer.

Sample
Input

2
0 0 4 4
1 1 3 3

Output

12

Input

4
0 0 10 10
1 1 11 11
2 2 12 12
3 3 13 13

Output

72

猜你喜欢

转载自blog.csdn.net/qq_43333395/article/details/89197770
今日推荐