srm 555

欢迎点此阅读QvQ

255


Description

问能将一个 0/1 串最少分成几个串使得每个串都是 5 的整数次幂,且没有前导零

Solution

dp即可,dp[i]表示前 i 个字符分割的结果,枚举一个分割点j check 即可

Code

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 55;
int dp[N];
struct CuttingBitString {
    bool ok(LL x) {
        while (x && x % 5 == 0) x /= 5;
        return x == 1;
    }
    int getmin(string S) {
        string s = "0" + S + "1";
        int n = s.size();
        for (int i = 1; i <= n; ++i)    dp[i] = 10000;
        for (int i = 1; i < n; ++i) {
            if (s[i] == '1') {
                for (int j = 0; j < i - 1; ++j) {
                    if (dp[j] == 10000 || s[j + 1] == '0')  continue;
                    LL now = 0;
                    for (int k = j + 1; k <= i - 1; ++k)    now = now * 2 + (s[k] == '1' ? 1 : 0);
                    if (ok(now))    dp[i - 1] = min(dp[i - 1], dp[j] + 1);
                }
            }
        }
        return dp[n - 2] == 10000 ? -1 : dp[n - 2];
    }
};

555


Description

有一个 HW 的全 0 矩阵,给定对行列操作数,每次操作将行列0/1翻转,使得最后矩阵 1 的个数为S,求方案数
两个方案不同当且仅当有一行或列操作数不同

Solution

很容易想到操作两次相当于没操作,枚举行列分别操作 1 次的个数,剩下的相当于n个物品(n对操作两次)放到 m 个不同盒子的方案数,即(n+m1n),统计即可

Code

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 1600, M = 555555555;
int c[N << 1][N << 1];
struct XorBoard {
    int count(int H, int W, int Rcount, int Ccount, int S) {
        for (int i = 0; i <= 1555 * 2; ++i) {
            c[i][0] = 1;
            for (int j = 1; j <= i; ++j)    c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % M;
        }
        int ans = 0;
        for (int i = 0; i <= Rcount && i <= H; ++i)
            for (int j = 0; j <= Ccount && j <= W; ++j) {
                if (i * W + j * H - 2 * i * j != S) continue;
                if ((Rcount - i) & 1 || (Ccount - j) & 1)   continue;
                int rl = (Rcount - i) / 2, cl = (Ccount - j) / 2;
                (ans += (LL)c[rl + H - 1][rl] * c[H][i] % M * c[cl + W - 1][cl] % M * c[W][j] % M) %= M;
            }
        return ans;
    }
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值