因为我是从上到下,所以就不叫动态规划而叫记忆化搜索吧

(不过运行时间只有3ms....应该是很不错的吧)

排版怎么那么难看。。。编辑的时候不是这样子的啊?!

思想 : 大眼一看应该是一道很裸的状压dp; 状态为填完每一列 每行%2的值 ; 状态的改变用异或就可以啦

我不是很会状压。。。有一个想法------状态是无序的 【我们只需要两个值】

k0(0的个数),k1(1的个数)来描述状态就可以啦。。

  1)状态描述:f[x][k0][k1]   在【1~(x-1)】列填好基础上填满整个方格

   要求填满方格之后 每行panda个数(从x列开始)%2==0个数为k0 ; ==1个数为k1

2) 状态转移:每列要求填a[i]个,a[i]个怎么分配呢?

         要求为0的方格填k个,要求为1的方格填a[i]-k;      

//状态转移
LL ans=;
for (int i=;i<=a[t];i++) {//有i个数放在了0的位置
if ( i<=k0 ) {
int t1=k0-i*+a[t]; //t1=k0-i+a[i]-0 0填一个表情变成1 1填一个变成0
int t2=k1+*i-a[t];
if (f[t+][t1][t2]<) //记忆化搜索
f[t+][t1][t2]=dfs (t1,t2,t+,sum-a[t]);
ans=( ans+C(k0,i)*C(k1,a[t]-i)%mod*f[t+][t1][t2]%mod )%mod;// c(k0,i)--》 从k0个位置选i个位置
}
}

3) 有个小优化的彩蛋哦。。。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=+;
const int mod=1e9+;
int a[N];
int n,m;
int cnt;
LL f[][][];
LL b[][];
LL C (int x, int y) {
if (y==) return ;
if (x-y<y) y=x-y;
if (b[x][y]) return b[x][y];
LL sum=;
LL k=;
for (int i=x-y+;i<=x;i++)
sum=sum*i/(k++);
b[x][y]=sum;
return sum;
}
LL dfs (int k0,int k1,int t,int sum) {
if (t==m) {
if (k1==a[t]) return ;
return ;
}
if (sum%!=k1%) return ;// 优化。。想想为什么呢?!
LL ans=;
for (int i=;i<=a[t];i++) {
if ( i<=k0 ) {
int t1=k0-i*+a[t];
int t2=k1+*i-a[t];
if (f[t+][t1][t2]<)
f[t+][t1][t2]=dfs (t1,t2,t+,sum-a[t]);
ans=( ans+C(k0,i)*C(k1,a[t]-i)%mod*f[t+][t1][t2]%mod )%mod;
}
}
return ans;
}
int main ()
{
while (~scanf ("%d %d",&n,&m)) {
int k0,k1;
memset (f,-,sizeof(f));
k1=k0=;
int sum=;
for (int i=;i<=m;i++) {
scanf ("%d",&a[i]);
sum+=a[i];
}
for (int i=;i<=n;i++) {
int x; scanf ("%d",&x);
if (x) k1++;
else k0++;
}
LL ans=dfs (k0,k1,,sum);
printf ("%lld\n",ans);
}
return ;
}

        

1117: Insert Orz Pandas

时间限制: 2 Sec  内存限制: 128 MB
提交: 32  解决: 12
[提交][状态][讨论版]

题目描述

Orz panda emotion is a famous emotion in XDU/ACM-ICPC QQ groups.
Big Big Xi loves to create new Orz panda emotions.
Now he has a matrix with n lines and m columns,form n*m cells.
And he wants to insert some small Orz pandas to this matrix to create a big emotion.
In each cell of the matrix,he will determine whether put a small Orz panda or not.
For some reasons,he has some special needs of the emotions:
1.In the ith column,there must be a[i] small Orz pandas. (1<=i<=m)
2.In the ith line,assume the total number of Orz pandas is x, x mod 2 must be b[i]. (1<=i<=n)
For example, if n=2 and m=3,a[1..3]={1,1,1},b[1..2]={1,0}

Now, Big Big Xi wants to know there are how many adapted ways to insert the pandas.

 

输入

There are multiple test cases (no more than 100,and no more than 10 test cases with large n and m), please process to EOF.

In each test case,there are two numbers N and M at the first line.(0<n<=10, 0<m<=100)

Then m lines, the ith line has a number indicates a[i].

And then n lines,the ith line has a number indicates b[i].

输出

One number which is the answer of the question (mod by 1e9+7)

样例输入

1 1
1
1
2 3
1
1
1
1
0

样例输出

1
4

xdoj-1117(记忆化搜索+组合数学)的更多相关文章

  1. 【10.31校内测试】【组合数学】【记忆化搜索/DP】【多起点多终点二进制拆位Spfa】

    Solution 注意取模!!! Code #include<bits/stdc++.h> #define mod 1000000007 #define LL long long usin ...

  2. [CSP-S模拟测试]:彩球问题(记忆化搜索)

    题目传送门(内部题91) 输入格式 第一行一个正整数$N$,表示颜色种类数. 第二行$N$个正整数$k[i],k[i]$表示第$i$种颜色的数量$(1\leqslant k[i]\leqslant 3 ...

  3. [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索

    1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...

  4. 【BZOJ-3895】取石子 记忆化搜索 + 博弈

    3895: 取石子 Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 263  Solved: 127[Submit][Status][Discuss] D ...

  5. hdu3555 Bomb (记忆化搜索 数位DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. zoj 3644(dp + 记忆化搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 思路:dp[i][j]表示当前节点在i,分数为j的路径条数,从 ...

  7. loj 1044(dp+记忆化搜索)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...

  8. DP(记忆化搜索) + AC自动机 LA 4126 Password Suspects

    题目传送门 题意:训练指南P250 分析:DFS记忆化搜索,范围或者说是图是已知的字串构成的自动机图,那么用 | (1 << i)表示包含第i个字串,如果长度为len,且st == (1 ...

  9. HDU1978 记忆化搜索

    How many ways Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. mysql索引简单分析

    索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将对整个表进 ...

  2. 逆袭之旅DAY30.XIA.集合

    2018年7月26日 面试题:List和set的区别 ArrayList 遍历效率较高,但添加和删除较慢 遍历集合最高效的方法:迭代器 集合的遍历: 迭代器:Iterator 创建 为什么使用泛型: ...

  3. 小程序swiper效果高宽设置(微信小程序交流群:604788754)

    swiper的宽和高一定要设置在swiper上面.swiper-item默认继承swiper的宽和高.swiper-item容器里面的宽和高没有继承他的父节点宽和高,需要从新设置. 不明白之处,可以咨 ...

  4. json模块&xml

    json模块将数据修改成字符串,方便其他语言进行识别. 只认双引号,不认单引号.使用json.dumps的操作步骤 先将单引号修改成单引号 将变量使用单引号引起来 将数据类型编程json字符串 jso ...

  5. 首席科学家马丁•福勒(Martin Fowler)

    现任思特沃克公司首席科学家的马丁·福勒先生是当今世界软件开发领域最具影响力的五位大师之一.作为一位敏捷软件开发方法的早期开拓者,福勒先生对IT 业的影响是不可估量的. 思特沃克公司是一家跨国专业IT ...

  6. angular4-事件绑定

    事件绑定语法(可以通过 (事件名) 的语法,实现事件绑定) <date-picker (dateChanged)="statement()"></date-pic ...

  7. python笔记6-while、for循环

    1.while--while循环之前,先判断一次,如果满足条件的话,再循环 #while循环 count=(input("请输入循环次数"))#计数器 while count< ...

  8. Centos7 LVM扩充存储空间

    一. 以root账户运行命令界面:su or su - 二.  查看分区使用情况: fdisk -l /dev/sda or fdisk -l 三. 选择要扩充的分区,以sda2为例: fdisk / ...

  9. netty源码理解(二) serverstrap.bind()

    eventloop是一个线程,里面有一个executor封装了一个线程工厂,在启动的时候启动一个线程,传入的实现了runnable的内部类,里面调用了eventloop的run方法.

  10. EF Code First MySql 主从表设计的一些需要注意的内容

    假如有下面两张表 public class Main { public int Id{get;set;} public string Name{get;set}; public virtual ICo ...