zoukankan      html  css  js  c++  java
  • HDU

    Samwell Tarly is learning to draw a magical matrix to protect himself from the White Walkers.
    the magical matrix is a matrix with n rows and m columns, and every single block should be painted either black or white.
    Sam wants to know how many ways to paint the matrix, satisfied that the final matrix has at least A rows, B columns was painted completely black. Cause the answer might be too big, you only need to output it modulo 998244353.

    InputThere might be multiple test cases, no more than 5. You need to read till the end of input.
    For each test case, a line containing four integers n,m,A,B.
    1n,m,A,B3000 1≤n,m,A,B≤3000 .
    OutputFor each test case, output a line containing the answer modulo 998244353.
    Sample Input

    3 4 1 2

    Sample Output

    169

    题意:给N*M的空白格子染色,求至少x行,至少y列被染色的方案数。

    思路:不会,占位。

    #include<bits/stdc++.h>
    using namespace std;
    #define LL long long
    const int maxn = 3001;
    const int MOD = 998244353;
    int n, m, A, B, ans;
    int C[maxn][maxn], two[maxn * maxn];
    int fa[maxn], fb[maxn];
    
    void Init() {
        for(int i = 0; i < maxn; ++i) {
            for(int j = 0; j <= i; ++j) {
                if(j == i || j == 0) {
                    C[i][j] = 1;
                } else {
                    C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
                    if(C[i][j] >= MOD) {
                        C[i][j] -= MOD;
                    }
                }
            }
        }
        two[0] = 1;
        for(int i = 1; i < maxn * maxn; ++i) {
            two[i] = two[i - 1] * 2;
            if(two[i] >= MOD) {
                two[i] -= MOD;
            }
        }
    }
    
    int main() {
        Init();
        while(~scanf("%d%d%d%d", &n, &m, &A, &B)) {
            ans = 0;
            for(int i = A; i <= n; ++i) {
                fa[i] = 0;
                for(int j = A; j < i; ++j) {
                    fa[i] = (fa[i] + (LL)C[i][j] * fa[j]) % MOD;
                }
                fa[i] = 1 - fa[i];
                if(fa[i] < 0) {
                    fa[i] += MOD;
                }
            }
            for(int i = B; i <= m; ++i) {
                fb[i] = 0;
                for(int j = B; j < i; ++j) {
                    fb[i] = (fb[i] + (LL)C[i][j] * fb[j]) % MOD;
                }
                fb[i] = 1 - fb[i];
                if(fb[i] < 0) {
                    fb[i] += MOD;
                }
            }
            for(int i = A; i <= n; ++i) {
                LL tmp = (LL)fa[i] * C[n][i] % MOD;
                for(int j = B; j <= m; ++j) {
                    ans = (ans + ((tmp * fb[j] % MOD) * C[m][j] % MOD) * two[(n - i) * (m - j)] % MOD) % MOD;
                }
            }
            printf("%d
    ", ans);
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    今天是周日,一如既往的在加班
    懒出来的框架
    把Visio文档中形状信息导出到XML文件的VBA代码
    DataGridView多线程更新数据的问题的解决办法
    为VS定制一个自己的代码生成器
    安装VS2012之后自己开发的自定义工具没法使用问题的解决办法
    通过RSA进行私钥加密公钥解密算法的进一步改进
    程序员在职场 该反思了吗?
    图片与字节数组相互转换的方法
    jQuery Ajax 方法调用 Asp.Net WebService 的详细例子
  • 原文地址:https://www.cnblogs.com/hua-dong/p/9851697.html
Copyright © 2011-2022 走看看