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 ...
随机推荐
- hasattr() & getattr() & setattr()
Python的hasattr() getattr() setattr() 函数使用方法详解 感谢作者 ---> 原文链接 hasattr(object, name) 判断一个对象里面是否有n ...
- perl连接mysql数据库
首先需要安装 ppm install DBD::mysql use strict; use DBI; my $host = "localhost"; # 主机地址 my $driv ...
- 十一、mysql老是停止运行该怎么解决
mysql老是停止运行该怎么解决 你可能还会遇到无法启动mysql的错误 解决方法如下:
- WebApi实现Ajax模拟Multipart/form-data方式多文件上传
前端页面代码: <input type="file" class="file_control" /><br /> <input t ...
- C# Json 序列化大全--任我行
public class JsonHelper { /// <summary> /// 将Model转换为Json字符串 /// </summary> /// <type ...
- 剑指Offer - 九度1366 - 栈的压入、弹出序列
剑指Offer - 九度1366 - 栈的压入.弹出序列2014-02-05 20:41 题目描述: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所 ...
- Nuget.config格式错误,请检查nuget.config配置文件
安装 VS 2015 Professional 版,安装后,我想加一个nuget的包配置. 然后提示我:Nuget.config格式错误,请检查nuget.config配置文件 我找到了 Nuget. ...
- Nuget的使用笔记-(使用nuget发布dll到www.nuget.org)
Nuget是神马东东? 来自nuget.org官方的介绍 ----------------------------------------------------------------------- ...
- Git上手:Git扫盲区
Git 自述Git 是由伟大的电脑程序员Linus Torvalds编写的一个开源的,分布式的版本控制系统软件. Git 核心原理Git 利用底层数据结构,通过指向索引对象的可变指针,保存文件快照. ...
- [转] Linux命令行编辑常用键
ctrl + a 将光标移动到命令行开头相当于VIM里shift+^ ctrl + e 将光标移动到命令行结尾处相当于VIM里shift+$ ctrl + 方向键左键 光标移动到前一个单词开头 ctr ...