E. XOR Triangle 数位dp

E. XOR Triangle 数位dp_第1张图片

 E. XOR Triangle 数位dp_第2张图片

 题意:

求出0

分析:

E. XOR Triangle 数位dp_第3张图片

 

#include
// cout< 
#define M(a,b) make_pair(a,b)
#define fi first
#define se second
#define pb push_back
#define __builtin_popcount popcnt1//getcnt 
#define db1(x) cerr<<#x<<"="<<(x)<<" "
#define db2(x) cerr<<#x<<"="<<(x)<<"\n"
#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll _gcd(ll a, ll b) { return b > 0 ? _gcd(b, a % b) : a; }
int popcnt1(ll x) { int ans = 0;for (int j = 0;j <= 60;j++)if (x & (1ll << j)) ans++;return ans; }
template  inline void read(T& t) { int f = 0, c = getchar(); t = 0;while (!isdigit(c)) f |= c == '-', c = getchar();while (isdigit(c)) t = t * 10 + c - 48, c = getchar();if (f) t = -t; }
template  void print(T x) { if (x < 0) x = -x, putchar('-');if (x > 9) print(x / 10);putchar(x % 10 + 48); }
const double pi = acos(-1.0);
const double eps = 1e-7;//有时候精度可能不够
const int inf = 0x3f3f3f3f;
const ll Inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int N = 3e5+10;
int n, m, t, k;
int a[N];
int dp[N][8][8];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s;
    cin >> s;
    dp[0][0][0] = 1;
    for (int i = 0;i < s.size();i++) {
        for (int j = 0;j < 8;j++) {
            for (int k = 0;k < 8;k++) {
                dp[i][j][k] %= mod;
                if (dp[i][j][k]) {
                    for (int l = 0;l < 8;l++) {
                        bool fg = 1;
                        for (int m = 0;m < 3;m++) {
                            if ((k & (1 << m)) == 0 && (l & (1 << m)) && s[i] == '0') {
                                fg = 0;break;
                            }
                        }
                        if (!fg) continue;
                        int j1 = j, k1 = k;
                        for (int m = 0;m < 3;m++) {
                            if (l == (1 << m) || ((l ^ (1 << m)) == 7)) {
                                j1 |= (1 << m);
                            }
                        }
                        for (int m = 0;m < 3;m++) {
                            if (s[i] == '1' && ((l & (1 << m)) == 0)) {
                                k1 |= (1 << m);
                            }
                        }
                        dp[i + 1][j1][k1] += dp[i][j][k];
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0;i < 8;i++) {
        ans += dp[s.size()][7][i];
    }
    cout << ans % mod << endl;
    return 0;
}

你可能感兴趣的:(java,开发语言)