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;
    }
  • 相关阅读:
    axios的拦截请求与响应
    Vue.mixin言简意赅的示例
    vue的formdata图片预览以及上传
    vue页面更新数据
    vue对象比较,阻止后退
    vue检索内容
    vue侧滑菜单
    JavaScript易错知识点整理
    写好你的JavaScript
    LeetCode123 Best Time to Buy and Sell Stock III
  • 原文地址:https://www.cnblogs.com/Commence/p/3992650.html
Copyright © 2011-2022 走看看