1 solutions

  • 0
    @ 2025-11-10 14:06:29

    计数

    显然是不可能真的一个一个计数的。我们首先还是考虑异或的性质问题。

    考察a, b, c 的每个数位,总共有8种情况,画个表:

    a b c a⊕ba\oplus b b⊕cb\oplus c a⊕ca\oplus c
    0 0 0 0 0
    1 1 1
    1 0 1 0
    1 0 0 1
    1 0 1
    0 1 1 0
    0 1 0 1
    1 0 0

    发现,对于每个数位,不管怎么选,总能满足a⊕b+b⊕c≥a⊕ca\oplus b + b\oplus c \ge a\oplus c。其余两个式子同理。

    这启发我们,其实只要每两个数字和第三个数字之间,至少能有一个数位使得大于号成立,就能满足这两个异或值的加和大于第三个异或值。

    上图中,能使得大于号取得满足仅有第三行和第六行。所以我们可以考虑数位DP,在做DP的同时维护当前能否使得$a\oplus b + b\oplus c \ge a\oplus c, a\oplus b + a\oplus c \ge b\oplus c, a\oplus c + b\oplus c \ge a\oplus b$。带着三个bool值转移即可。

    总复杂度O(23∗23∗23∗n)O(2^3 * 2^3 * 2^3 * n)。

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 2e5 + 5;
    const int mod = 998244353;
    char a[N];
    int n, dp[N][2][2][2][2][2][2];
    inline int dfs(int k, bool l1, bool l2, bool l3, bool _x, bool _y, bool _z)
    {
    	if (k > n)
    		return _x && _y && _z;
    	if (dp[k][l1][l2][l3][_x][_y][_z] != -1)
    		return dp[k][l1][l2][l3][_x][_y][_z];
    	int res = 0;
    	for (int x = 0; x <= (l1 ? a[k] - '0' : 1); x++)
    		for (int y = 0; y <= (l2 ? a[k] - '0' : 1); y++)
    			for (int z = 0; z <= (l3 ? a[k] - '0' : 1); z++)
    				res = (res + 
    						dfs(k + 1, l1 & (x == a[k] - '0'), 
    							l2 & (y == a[k] - '0'), l3 & (z == a[k] - '0'), 
    							_x | (x == 0 && y == 1 && z == 1) | (x == 1 && y == 0 && z == 0), 
    							_y | (y == 0 && x == 1 && z == 1) | (y == 1 && x == 0 && z == 0), 
    							_z | (z == 0 && x == 1 && y == 1) | (z == 1 && x == 0 && y == 0)
    						)
    					) % mod;
    	return dp[k][l1][l2][l3][_x][_y][_z] = res;
    }
    int main()
    {
    	scanf("%s", a + 1);
    	n = strlen(a + 1);
    	memset(dp, -1, sizeof dp);
    	printf("%d\n", dfs(1, 1, 1, 1, 0, 0, 0));
    	return 0;
    }
    
    • 1

    Information

    ID
    136
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    9
    Tags
    (None)
    # Submissions
    12
    Accepted
    7
    Uploaded By