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 == ? 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的更多相关文章
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- UVA 11481 Arrange the Numbers(组合数学 错位排序)
题意:长度为n的序列,前m位恰好k位正确排序,求方法数 前m位选k个数正确排,为cm[m][k],剩余m - k个空位,要错排,这m - k个数可能是前m个数中剩下的,也可能来自后面的n - m个数 ...
- UVA 11481 - Arrange the Numbers 数学
Consider this sequence {1, 2, 3, . . . , N}, as a initial sequence of first N natural numbers. You ca ...
- UVa 11481 Arrange the Numbers (组合数学)
题意:给定 n,m,k,问你在 1 ~ n 的排列中,前 m 个恰好有 k 个不在自己位置的排列有多少个. 析:枚举 m+1 ~ n 中有多少个恰好在自己位置,这个是C(n-m, i),然后前面选出 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- UVA1620-Lazy Susan(思维+逆序对)
Problem UVA1620-Lazy Susan Accept: 81 Submit: 375Time Limit: 3000 mSec Problem Description There ar ...
- 集训第四周(高效算法设计)P题 (构造题)
Description There are N<tex2html_verbatim_mark> marbles, which are labeled 1, 2,..., N<te ...
- UVA 10090 - Marbles 拓展欧几里得
I have some (say, n) marbles (small glass balls) and I am going to buy some boxes to store them. The ...
- uva 10090 Marbles
Problem F Marbles Input: standard input Output: standard output I have some (say, n) marbles (small ...
随机推荐
- 模块hashlib和logging
Python的hashlib提供了常见的摘要算法MD5. 我们以常见的摘要算法MD5为例,计算出一个字符串的MD5值: import hashlib md5=hashlib.md5() md5.upd ...
- SQL语句知识点
PERSON表 NUMBER NAME SEX AGE 1 THERON male 19 2 JACK male 20 3 LUCY female 20 1.SELECT选择 SELECT 列 ...
- Kotlin 二分法算法游戏--猜价格
本人最新想学习算法,算法是提高程序性能的关键! 程序就是数据结构和算法! 写了一个二分法的游戏,供大家参考: 当然,语言基于kotlin import java.util.* /** * Create ...
- Python语法之com[1][:-7]
strCom = com[0] + ": " + com[1][:-7] 如上应该是一个字符串合成,最后的[1][:-7],我理解是去除com[1]的最后7个字符. 比如com[0 ...
- centos7.3配置guacamole
目录 1 安装guacamole所需要的依赖库 2 安装配置tomcat,架设服务 2.1 下载tomcat 2.2 配置环境变量,使tomcat可以找到guacamole客户端配置 2.3 安装gu ...
- Spring mvc+hibernate+freemarker(实战)
Spring mvc+hibernate+freemarker(实战) 博客分类: Spring Spring mvchibernatefreemarkerwebjava 今天我为大家做了一个 sp ...
- CV限制符--C++
C/C++提供多种声明变量和函数存储持续性.作用域和链接性的关键字,有些被称为存储说明符(store class specifier)或 cv 限定符(cv-qualifier),这里就一起学习一下c ...
- pytest 运行指定用例
pytest运行指定用例 随着软件功能的增加,模块越来越多,也意味用例越来越多,为了节约执行时间,快速得到测试报告与结果,在工作中可以通过运行指定用例,达到快速执行用例 例子目录 spec_sub1_ ...
- Microsxxxxxxx-面试总结
策略题 There are four kinds of cards, respectively, 1,2, 3,4 numbers. There are seven cards for each ty ...
- 求:斐波那契数列的第n项
def he (n): if n < 3 : return 1 return he(n-1)+he(n-2)print(he(n))