[比赛题解] Codeforces Round 940 (Div 2) and CodeCraft- 949676b86e1241c7ad1e7f9102221f4f

[比赛题解] Codeforces Round 940 (Div. 2) and CodeCraft-23

比赛链接:Codeforces Round 940 (Div. 2) and CodeCraft-23 - Codeforces

C. How Does the Rook Move?

经过若干步合法步骤后,答案可以看作在空白的 n × n n\times n n×n棋盘上放置棋子。

考虑 n × n n\times n n×n棋盘上第一行被什么占据:

(1) 被 ( 1 , 1 ) (1,1) (1,1)的白棋占据,则剩余一个 ( n − 1 ) × ( n − 1 ) (n-1)\times(n-1) (n1)×(n1)棋盘。

(2) 被 ( 1 , i ) (1,i) (1,i) ( i , 1 ) (i,1) (i,1)的白棋占据,剩余一个 ( n − 2 ) × ( n − 2 ) (n-2)\times(n-2) (n2)×(n2)棋盘。

设方案数为 d p [ n ] dp[n] dp[n],得到dp方程 d p [ n ] = d p [ n − 1 ] + 2 ( i − 1 ) d p [ n − 2 ] dp[n]=dp[n-1]+2(i-1)dp[n-2] dp[n]=dp[n1]+2(i1)dp[n2]

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

const int MAXN = 300000+5;
const int N = 300000;
const int mod = 1e9+7;
int T, n, k;
int dp[MAXN];

int main(){
   
   
    dp[0] = dp[1] = 1;
    for(int i = 2; i <= N; i++){
   
   
        dp[i] = (dp[i-1] + (ll)dp[i-2]*2*(i-1)) % mod;
    }
    scanf("%d", &T);
    while(T--){
   
   
        scanf("%d%d", &n, &k);
        while(k--){
   
   
            int x, y;
            scanf("%d%d", &x, &y);
            if(x == y)  n--;
            else  n -= 2;
        }
        printf("%d\n", dp[n]);
    }
    return 0;
}

D. A BIT of an Inequality

按二进制位考虑,若有 f ( x , y ) ⊕ f ( y , z ) > f ( x , z ) f(x,y)\oplus f(y,z)>f(x,z) f(x,y)f(y,z)>f(x,z),则在 a y a_y ay的最高二进制位上, a x ⊕ a x + 1 ⊕ ⋯ ⊕ a z a_x\oplus a_{x+1}\oplus\dots\oplus a_z axax+1az 在该位为 0 0 0。即在该二进制位上, a [ x , y ) a[x,y) a[x,y)内1的个数加 a ( y , z ] a(y,z] a(y,z]内1的个数为奇数,统计每个二进制位上使得 a [ i , y ) a[i,y) a[i,y)内1的个数为奇数和使得 a ( y , i ] a(y,i] a(y,i]内1的个数为奇数的 i i i的个数,即可计算答案。

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

const int MAXN = 100000+5;
int T, n;
int a[MAXN], cl[40], cr[40], cnt[40];
ll ans
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值