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 ...
随机推荐
- POJ-3126 BFS,埃式筛选及黑科技
题目大意:给定两个四位素数a b,要求把a变换到b,变换的过程要保证 每次变换出来的数都是一个 四位素数,而且当前这步的变换所得的素数 与 前一步得到的素数 只能有一个位不同,而且每步得到的 ...
- 菜鸟教程perl总结
数据类型有: 标量$, 数组@,哈希% 数组声明 : @hits = (25, 30, 40); 或者 @sites = qw/google taobao runoob/; 数组操作 pop, ...
- TouTiao开源项目 分析笔记9 实现一个问答主页面
1.根据API返回创建几个基础的Bean 1.1.WendaArticleDataBean类 API返回的数据如下: /** * cell_type : 36 * extra : {"wen ...
- 九、MySQL 5.7.9版本sql_mode=only_full_group_by问题
MySQL 5.7.9版本sql_mode=only_full_group_by问题 用到GROUP BY 语句查询时com.mysql.jdbc.exceptions.jdbc4.MySQLSynt ...
- 2 实现第一个Django网站 博客
-1.理解上下文 render()渲染 request url传来的reuqest x.html 制定返回的模板名称 context 上下文 数据库中 替换数据 0.大框架 1.创建模板 (1 ...
- 一个初学者的辛酸路程-依旧Django
回顾: 1.Django的请求声明周期? 请求过来,先到URL,URL这里写了一大堆路由关系映射,如果匹配成功,执行对应的函数,或者执行类里面对应的方法,FBV和CBV,本质上返回的内容都是字符串 ...
- linux shell 总结 (整理)
ls /usr/bin/ info #路径操作 dirname basename #“”和‘’与 ` ` 在shell变量中的区别 “ ” 允许通过$符引用其他变量 ‘’禁止引用其他变量符,视为普通字 ...
- Python3基本语法
#编码 ''' 默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串. 当然你也可以为源码文件指定不同的编码: # -*- coding: cp-1252 ...
- mysql中查询常用的关键字
最简单的查询: 1 select * from [where ] 1 select column1,column2....from [where] 这里需要注意的是where子句中条件过滤使用到的关键 ...
- php中变量的详细介绍
变量的含义: 用于存储信息的容器,在程序运行期间,可以变化的量 变量的命名规则: 1.变量以$符开始 2.变量名只能以字母或下划线开始 3.变量名只能是字母,下划线,数字,不能有特殊字符:逗号,句号, ...