zoukankan      html  css  js  c++  java
  • UVA 11125 Arrange Some Marbles

    dp[i][j][m][n][s]表示最初选择j个i号颜色大理石。当前选择n个m号颜色大理石。剩余大理石状态(8进制数状压表示)最开始没看出状压。。sad

    #include <map>
    #include <set>
    #include <list>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <stack>
    #include <queue>
    #include <cctype>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <climits>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define LL long long
    #define PI 3.1415926535897932626
    using namespace std;
    int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
    int base_8[]={1 ,8 ,64 ,512};
    int cnt[4],dp[4][4][4][4][5000];
    int N;
    int calcu(int hc, int hl, int pc, int pl, int sta)
    {
        if (dp[hc][hl][pc][pl][sta]!=-1) return dp[hc][hl][pc][pl][sta];
        dp[hc][hl][pc][pl][sta]=0;
        if (sta == 0)
        {
            if (hc != pc && hl != pl) return dp[hc][hl][pc][pl][sta] = 1;
            else return dp[hc][hl][pc][pl][sta] = 0;
        }
        for (int i = 0; i < N; i++)
            for (int j = 1; j <= 3 && j <= cnt[i]; j++)
        {
            if (i != pc && j != pl)
            {
                cnt[i] -= j;
                dp[hc][hl][pc][pl][sta] += calcu(hc, hl, i, j, sta - base_8[i] * j);
                cnt[i] += j;
            }
        }
        return dp[hc][hl][pc][pl][sta];
    }
    int slove()
    {
        int state=0,ans=0;
        for (int i = N - 1; i >= 0; i--) state = state * 8 + cnt[i];
        for (int i = 0; i < N; i++)
            for (int j = 1; j <= 3 && j <= cnt[i]; j++)
        ans += calcu(i, j, i, j,state - j * base_8[i]);
        return ans;
    }
    int main()
    {
        int T;
        memset(dp,-1,sizeof(dp));
        scanf("%d",&T);
        while (T--)
        {
            scanf("%d",&N);
            for (int i = 0; i < N; i++) scanf("%d",&cnt[i]);
            if (cnt[0] == 0 && cnt[1] == 0 && cnt[2] == 0 && cnt[3] == 0) puts("1");
            else  printf("%d
    ",slove());
        }
        return 0;
    }
  • 相关阅读:
    mysql 全量备份和增量备份
    mysql 修改密码提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    MHA 常见问题解决
    MHA 数据库高可用+ GTID 同步测试部署
    通过电脑抓手机端log
    用js递归遍历树结构
    js实现全屏
    使表格随着内容自适应宽度
    POST请求
    vue中组件通信
  • 原文地址:https://www.cnblogs.com/Commence/p/3992650.html
Copyright © 2011-2022 走看看