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 ...
随机推荐
- Ubuntu 16.04上安装并配置Postfix作为只发送SMTP服务器
如果大家已经在使用第三方邮件服务方案发送并收取邮件,则无需运行自己的邮件服务器.然而,如果大家管理一套云服务器,且其中安装的应用需要发送邮件通知,那么运行一套本地只发送SMTP服务器则更为理想. 如何 ...
- 12,DBUtils - Python数据库连接池
创建数据库连接池: import time import pymysql import threading from DBUtils.PooledDB import PooledDB, SharedD ...
- SpringMVC---其它常用注解
常用注解 PathVariable @RequestMapping注解中使用占位符的情况下,需要使用@PathVariable注解指定占位符参数.即指定占位符中的值与方法中哪一个参数进行匹配.如果方法 ...
- java 中实体Bean和Map互相转化
技术交流群: 233513714 // 将一个map对象转化为bean public static void transMap2Bean(Map<String, Object> map, ...
- TP5 中出现 No input file specified
之前用php5.4 更新至php7之后原tp5项目出现 No input file specified 修改方法: 打开public目录下的.htaccess文件,把:RewriteRule ^(.* ...
- How to send CTRL+BREAK signal to detached command-line process
1.GenerateConsoleCtrlEvent function Sends a specified signal to a console process group that shares ...
- 【NOIP 2017 提高组】列队
题目 有一个 \(n\times m\) 的方阵,每次出来一个人后向左看齐,向前看齐,询问每次出来的人的编号. \(n\le 3\times 10^5\) 分析 我们考虑离队本质上只有两种操作: 删除 ...
- lshw
https://linux.die.net/man/1/lshw lshw(Hardware Lister)是另外一个可以查看硬件信息的工具,不仅如此,它还可以用来做一些硬件的benchmark. 这 ...
- sources.list
deb http://debian.ustc.edu.cn/ubuntu/ precise main multiverse restricted universe deb http://debian. ...
- ThreadLocal 学习
JDK 1.2版本就已经提供了java.lang.ThreadLocal.其为多线程程序的并发问题提供了一种新的思路.使用该工具类可以简洁地编写出优美的多线程程序. 当使用ThreadLocal维护变 ...