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 == ? b : gcd(b, a % b);}
int base_8[]={ , , ,};
int cnt[],dp[][][][][];
int N;
int calcu(int hc, int hl, int pc, int pl, int sta)
{
if (dp[hc][hl][pc][pl][sta]!=-) return dp[hc][hl][pc][pl][sta];
dp[hc][hl][pc][pl][sta]=;
if (sta == )
{
if (hc != pc && hl != pl) return dp[hc][hl][pc][pl][sta] = ;
else return dp[hc][hl][pc][pl][sta] = ;
}
for (int i = ; i < N; i++)
for (int j = ; j <= && 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=,ans=;
for (int i = N - ; i >= ; i--) state = state * + cnt[i];
for (int i = ; i < N; i++)
for (int j = ; j <= && j <= cnt[i]; j++)
ans += calcu(i, j, i, j,state - j * base_8[i]);
return ans;
}
int main()
{
int T;
memset(dp,-,sizeof(dp));
scanf("%d",&T);
while (T--)
{
scanf("%d",&N);
for (int i = ; i < N; i++) scanf("%d",&cnt[i]);
if (cnt[] == && cnt[] == && cnt[] == && cnt[] == ) puts("");
else printf("%d\n",slove());
}
return ;
}

UVA 11125 Arrange Some Marbles的更多相关文章

  1. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  2. UVA 11481 Arrange the Numbers(组合数学 错位排序)

    题意:长度为n的序列,前m位恰好k位正确排序,求方法数 前m位选k个数正确排,为cm[m][k],剩余m - k个空位,要错排,这m - k个数可能是前m个数中剩下的,也可能来自后面的n - m个数 ...

  3. UVA 11481 - Arrange the Numbers 数学

    Consider this sequence {1, 2, 3, . . . , N}, as a initial sequence of first N natural numbers. You ca ...

  4. UVa 11481 Arrange the Numbers (组合数学)

    题意:给定 n,m,k,问你在 1 ~ n 的排列中,前 m 个恰好有 k 个不在自己位置的排列有多少个. 析:枚举 m+1 ~ n 中有多少个恰好在自己位置,这个是C(n-m, i),然后前面选出 ...

  5. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  6. UVA1620-Lazy Susan(思维+逆序对)

    Problem UVA1620-Lazy Susan Accept: 81  Submit: 375Time Limit: 3000 mSec Problem Description There ar ...

  7. 集训第四周(高效算法设计)P题 (构造题)

    Description   There are N<tex2html_verbatim_mark> marbles, which are labeled 1, 2,..., N<te ...

  8. UVA 10090 - Marbles 拓展欧几里得

    I have some (say, n) marbles (small glass balls) and I am going to buy some boxes to store them. The ...

  9. uva 10090 Marbles

    Problem F Marbles Input: standard input Output: standard output I have some (say, n) marbles (small ...

随机推荐

  1. 大话CNN经典模型:AlexNet

    2012年,Alex Krizhevsky.Ilya Sutskever在多伦多大学Geoff Hinton的实验室设计出了一个深层的卷积神经网络AlexNet,夺得了2012年ImageNet LS ...

  2. 6.定制10MINS首页1

    原始代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...

  3. 亲手搭建一个基于Asp.Net WebApi的项目基础框架2

    本篇目的:封装一些抽象类 1::封装日志相关类 2:封装一个Service操作类 3:封装缓存操作类 4:封装其他一些常用Helper 1.1在Framework项目里面建立好相关操作类文件夹,以便于 ...

  4. Web安全2--XSS&CSRF

    1.XSS(跨站脚本攻击) 跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS ...

  5. 设置虚拟wifi,手机和电脑可以连接

    在家里没有wifi,笔记本电脑又是宽带连接,有时候手机流量用得很快,于是网上找了一下设置虚拟wifi 方法. 1.首先你的电脑上要有无线网卡,并且无线网上一定要是开户的,一般默认的都开启,如果没有开启 ...

  6. ios开发3.5和4.0寸屏幕自适应中的一点问题

    在开发iso应用中需要考虑到ip4的3.5寸屏幕和ip5的4寸屏幕的高度不一样的问题.常见的问题有滚动条位置,底部被挡住等情况:我遇见是tableview中添加下拉上提刷新功能时刷新指示器显示位置的问 ...

  7. leetcode 【 Remove Nth Node From End of List 】 python 实现

    题目: Given a linked list, remove the nth node from the end of list and return its head. For example, ...

  8. FTP2

    FTP: 环境:windows, python 3.5功能:1.用户加密认证,可自行配置家目录磁盘大小2.多用户登陆3.查看当前目录(家目录权限下)4.切换目录(家目录权限下)5.上传下载,进度条展示 ...

  9. UVALive 5029 字典树

    E - Encoded Barcodes Crawling in process...Crawling failedTime Limit:3000MS    Memory Limit:0KB    6 ...

  10. nyoj 题目61 传纸条

    传纸条(一) 时间限制:2000 ms  |  内存限制:65535 KB 难度:5   描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行 ...