dp[i][j][m][n][s]表示最初选择j个i号颜色大理石。当前选择n个m号颜色大理石。剩余大理石状态(8进制数状压表示)最开始没看出状压。。sad

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <deque>
  7. #include <stack>
  8. #include <queue>
  9. #include <cctype>
  10. #include <cstdio>
  11. #include <string>
  12. #include <vector>
  13. #include <climits>
  14. #include <cstdlib>
  15. #include <cstring>
  16. #include <iostream>
  17. #include <algorithm>
  18. #define LL long long
  19. #define PI 3.1415926535897932626
  20. using namespace std;
  21. int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
  22. int base_8[]={ , , ,};
  23. int cnt[],dp[][][][][];
  24. int N;
  25. int calcu(int hc, int hl, int pc, int pl, int sta)
  26. {
  27. if (dp[hc][hl][pc][pl][sta]!=-) return dp[hc][hl][pc][pl][sta];
  28. dp[hc][hl][pc][pl][sta]=;
  29. if (sta == )
  30. {
  31. if (hc != pc && hl != pl) return dp[hc][hl][pc][pl][sta] = ;
  32. else return dp[hc][hl][pc][pl][sta] = ;
  33. }
  34. for (int i = ; i < N; i++)
  35. for (int j = ; j <= && j <= cnt[i]; j++)
  36. {
  37. if (i != pc && j != pl)
  38. {
  39. cnt[i] -= j;
  40. dp[hc][hl][pc][pl][sta] += calcu(hc, hl, i, j, sta - base_8[i] * j);
  41. cnt[i] += j;
  42. }
  43. }
  44. return dp[hc][hl][pc][pl][sta];
  45. }
  46. int slove()
  47. {
  48. int state=,ans=;
  49. for (int i = N - ; i >= ; i--) state = state * + cnt[i];
  50. for (int i = ; i < N; i++)
  51. for (int j = ; j <= && j <= cnt[i]; j++)
  52. ans += calcu(i, j, i, j,state - j * base_8[i]);
  53. return ans;
  54. }
  55. int main()
  56. {
  57. int T;
  58. memset(dp,-,sizeof(dp));
  59. scanf("%d",&T);
  60. while (T--)
  61. {
  62. scanf("%d",&N);
  63. for (int i = ; i < N; i++) scanf("%d",&cnt[i]);
  64. if (cnt[] == && cnt[] == && cnt[] == && cnt[] == ) puts("");
  65. else printf("%d\n",slove());
  66. }
  67. return ;
  68. }

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. hasattr() & getattr() & setattr()

    Python的hasattr() getattr() setattr() 函数使用方法详解   感谢作者 ---> 原文链接 hasattr(object, name) 判断一个对象里面是否有n ...

  2. perl连接mysql数据库

    首先需要安装 ppm install DBD::mysql use strict; use DBI; my $host = "localhost"; # 主机地址 my $driv ...

  3. 十一、mysql老是停止运行该怎么解决

    mysql老是停止运行该怎么解决 你可能还会遇到无法启动mysql的错误 解决方法如下:      

  4. WebApi实现Ajax模拟Multipart/form-data方式多文件上传

    前端页面代码: <input type="file" class="file_control" /><br /> <input t ...

  5. C# Json 序列化大全--任我行

    public class JsonHelper { /// <summary> /// 将Model转换为Json字符串 /// </summary> /// <type ...

  6. 剑指Offer - 九度1366 - 栈的压入、弹出序列

    剑指Offer - 九度1366 - 栈的压入.弹出序列2014-02-05 20:41 题目描述: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所 ...

  7. Nuget.config格式错误,请检查nuget.config配置文件

    安装 VS 2015 Professional 版,安装后,我想加一个nuget的包配置. 然后提示我:Nuget.config格式错误,请检查nuget.config配置文件 我找到了 Nuget. ...

  8. Nuget的使用笔记-(使用nuget发布dll到www.nuget.org)

    Nuget是神马东东? 来自nuget.org官方的介绍 ----------------------------------------------------------------------- ...

  9. Git上手:Git扫盲区

    Git 自述Git 是由伟大的电脑程序员Linus Torvalds编写的一个开源的,分布式的版本控制系统软件. Git 核心原理Git 利用底层数据结构,通过指向索引对象的可变指针,保存文件快照. ...

  10. [转] Linux命令行编辑常用键

    ctrl + a 将光标移动到命令行开头相当于VIM里shift+^ ctrl + e 将光标移动到命令行结尾处相当于VIM里shift+$ ctrl + 方向键左键 光标移动到前一个单词开头 ctr ...