http://codeforces.com/gym/100405

D题

题在pdf里

codeforces.com/gym/100405/attachments/download/2331/20132014-acmicpc-northwestern-european-regional-contest-nwerc-13-en.pdf

D - Diagrams & Tableaux
A Young diagram is an arrangement of boxes in rows and columns conforming to the following
rules:
the boxes in each row and each column are contiguous,
the left borders of all rows are aligned, and
each row is not longer than the one above.
Here are some examples of Young diagrams:
A semi-standard Young tableau for a given number N is a Young diagram that has its boxes
filled according to the following rules:
Each box contains a single integer between 1 and N, inclusive,
each integer is greater than or equal to the integer in the box to its left, and
each integer is strictly greater than the integer in the box above.
Here is a list of all semi-standard Young tableaux for N = 3, based on a particular Young
diagram:
1
2
1 1
3
1 1
2
2 1
3
2 1
2
3 1
3
3 2
3
2 2
3
3
Your task is to count how many semi-standard Young tableaux are possible, based on a given
Young diagram, with a given N.
Input
Each test case consists of two lines. The first line of each test case specifies the Young diagram.
This line starts with the number k satisfying 1 k 7, the number of rows, followed by k
positive integers l1, l2, . . . , lk. These integers specify the number of boxes on each row of the
Young diagram, and they satisfy 7 l1 l2 lk 1. The second line contains the
integer N, satisfying k N 7.
Output
For each test case, print one line containing the number of semi-standard Young tableaux
based on the given Young diagram, with the given N.
9
Problem D: Diagrams & Tableaux
Example
input output
1 1
1
1 1
2
2 2 1
4
4 3 2 1 1
4
1
2
20
20
10

题意:

给出一个那种形状,由很多个方格组成。每个方格中可以放1~N中的一个数,要求方格中的数大于上面相邻方格中的数,大于等于左边相邻方格的数。求有多少种放法。

给出k,表示有k行,然后给出各行的方格数。然后给出N。

题解:

状压DP。

因为一列要求下面大于上面,即不能等于,每种数字只能用一次,可以用状态的二进制位表示有无哪个数字,于是2^7=128,用0~127就能表示一列的所有状态。

然后状态转移,相邻两列转,枚举所有情况也就127^2。

然后一共最多7列,转转就得了。

注意结果大,用long long。

代码:

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
const double pi=acos(-1.0);
const double eps=1e-; int k,n;
int a[]; //int cntt[133];
int cnt(int st) {
//if(cntt[st]!=-1)return cntt[st];
int t=,tt=st;
while(tt) {
if(tt&)t++;
tt>>=;
}
//cntt[st]=t;
return t;
} //int okk[133][133];
int ok(int j,int k) {
//if(okk[j][k]!=-1)return okk[j][k];
if(cnt(j)<cnt(k)) {
//okk[j][k]=0;
return ;
}
int tk=k,tj=j,ck=,cj=;
while(tk) {
if(tk&==) {
while(tj) {
if(tj&==) {
if(cj>ck) {
//okk[j][k]=0;
return ;
}
cj++;
tj>>=;
break;
}
cj++;
tj>>=;
if(!tj)while();
}
}
ck++;
tk>>=;
}
//okk[j][k]=1;
return ;
} ll d[][];
int c[],mj; ll farm() {
int i,j;
int maxst=<<n;
//printf("maxst = %d\n",maxst);
mz(d);
FOR(k,,maxst-)
if(cnt(k)==c[])d[][k]=; FOR(i,,mj) {
FOR(j,,maxst-) {
FOR(k,,maxst-) {
if(d[i-][j]!= && cnt(k)==c[i] && cnt(j)==c[i-] && ok(j,k)) {
d[i][k]+=d[i-][j];
//printf("d[%d][%x]=%I64d , d[%d][%x]=%I64d\n",i-1,j,d[i-1][j] ,i,k,d[i][k]);
}
}
}
}
ll re=;
FOR(i,,maxst-)re+=d[mj][i];
return re;
} int main() {
int i,j;
//mf1(cntt);
//mf1(okk);
while(RD(k)!=EOF) {
mz(c);
FOR(i,,k) {
RD(a[i]);
FOR(j,,a[i])c[j]++;
}
mj=a[];
RD(n);
printf("%I64d\n",farm());
}
return ;
}

codeforces Diagrams & Tableaux1 (状压DP)的更多相关文章

  1. UVaLive 6625 Diagrams & Tableaux (状压DP 或者 DFS暴力)

    题意:给一个的格子图,有 n 行单元格,每行有a[i]个格子,要求往格子中填1~m的数字,要求每个数字大于等于左边的数字,大于上边的数字,问有多少种填充方法. 析:感觉像个DP,但是不会啊...就想暴 ...

  2. codeforces#1215E. Marbles(状压DP)

    题目大意:给出一个由N个整数组成的序列,通过每次交换相邻的两个数,使这个序列的每个相同的数都相邻.求最小的交换次数. 比如给出序列:1 2 3 2 1 ,那么最终序列应该是 1 1 2 2 3 ,最小 ...

  3. codeforces 11D(状压dp)

    传送门:https://codeforces.com/problemset/problem/11/D 题意: 求n个点m条边的图里面环的个数 题解: 点的范围只有19,很容易想到是状压. dp[sta ...

  4. Codeforces Gym 100015F Fighting for Triangles 状压DP

    Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...

  5. Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

    Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...

  6. 状压dp Codeforces Beta Round #8 C

    http://codeforces.com/contest/8/problem/C 题目大意:给你一个坐标系,给你一个人的目前的坐标(该坐标也是垃圾桶的坐标),再给你n个垃圾的坐标,这个人要捡完所有的 ...

  7. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  8. Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)

    http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...

  9. Codeforces Beta Round #8 C. Looking for Order 状压dp

    题目链接: http://codeforces.com/problemset/problem/8/C C. Looking for Order time limit per test:4 second ...

随机推荐

  1. 【caffe】train_lenet.sh在windows下的解决方案

    @tags: caffe python 在windows下配置caffe后,跑mnist手写数字识别的例子.发现train_lenet.sh不能运行. 那就写个python脚本替代吧. step1 定 ...

  2. 【BZOJ-2177】曼哈顿最小生成树 Kruskal + 树状数组

    2177: 曼哈顿最小生成树 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 190  Solved: 77[Submit][Status][Discu ...

  3. Genymotion关于【启动后player.exe已停止运行】解决方案总结

    1. 你硬盘空间不足,或是暂存区不够,请少执行一些程序或关掉一些p2p的程序,或是到控制面板卸载一些不必要的程序.最好的建议是定期进行硬盘清理,确保不浪费多余空间 ---以上来源(http://www ...

  4. String、StringBuffer、StringBuilder源码分析

    利用反编译具体看看"+"的过程 1 public class Test 2 { 3 public static void main(String[] args) 4 { 5 int ...

  5. [JavaEE] NIO与IO的区别

    nio是new io的简称,从jdk1.4就被引入了.现在的jdk已经到了1.6了,可以说不是什么新东西了.但其中的一些思想值得我来研究.这两天,我研究了下其中的套接字部分,有一些心得,在此分享. 首 ...

  6. Beta版本冲刺第一天 12.5

    一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 前段时间完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 对Alpha版本的分析总结,学习新技术,对Beta版本的讨论规 ...

  7. Beta版本冲刺第五天 12.11

    一.站立式会议照片: 二.项目燃尽图: Android端 后台 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 管理员驳回招聘的理由的填写和查看 邮箱验证 ...

  8. LAMP-五分钟搭建个人论坛

    LAMP-五分钟搭建个人论坛 系统版本:CentOS7 1.##安装lamp及依赖软件wget http://repo.mysql.com/mysql-community-release-el7-5. ...

  9. web中异步和同步的理解

    普通的B/S模式就是同步,而AJAX技术就是异步,当然XMLHttpReques有同步的选项. 同步:提交请求->等待服务器处理->处理完毕返回.这个期间客户端浏览器不能干任何事. 异步: ...

  10. 通过Nginx,Tomcat访问日志(access log)记录请求耗时

    一.Nginx通过$upstream_response_time $request_time统计请求和后台服务响应时间 nginx.conf使用配置方式: log_format main '$remo ...