spoj-ASSIGN-bitDP
ASSIGN - Assignments
Problem
Your task will be to calculate number of different assignments of n different topics to n students such that everybody gets exactly one topic he likes.
Input
First line of input contains number of test cases c (1<=c<=80). Each test case begins with number of students n (1<=n<=20). Each of the next n lines contains n integers describing preferences of one student. 1 at the ith position means that this student likes ith topic, 0 means that he definitely doesn't want to take it.
Output
For each test case output number of different assignments (it will fit in a signed 64-bit integer).
Example
Input:
3
3
1 1 1
1 1 1
1 1 1
11
1 0 0 1 0 0 0 0 0 1 1
1 1 1 1 1 0 1 0 1 0 0
1 0 0 1 0 0 1 1 0 1 0
1 0 1 1 1 0 1 1 0 1 1
0 1 1 1 0 1 0 0 1 1 1
1 1 1 0 0 1 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 1
1 0 1 1 0 0 0 0 0 0 1
0 0 1 0 1 1 0 0 0 1 1
1 1 1 0 0 0 1 0 1 0 1
1 0 0 0 1 1 1 1 0 0 0
11
0 1 1 1 0 1 0 0 0 1 0
0 0 1 1 1 1 1 1 1 1 1
1 1 0 1 0 0 0 0 0 1 0
0 1 0 1 0 1 0 1 0 1 1
1 0 0 1 0 0 0 0 1 0 1
0 0 1 0 1 1 0 0 0 0 1
1 0 1 0 1 1 1 0 1 1 0
1 0 1 1 0 1 1 0 0 1 0
0 0 1 1 0 1 1 1 1 1 1
0 1 0 0 0 0 0 0 0 1 1
0 1 1 0 0 0 0 0 1 0 1 Output:
6
7588
7426
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
long long f[][(<<)+];
int e[][];
int main()
{
int t,n,m,i,j,k;
cin>>t;
while(t--){
cin>>n;
for(i=;i<=n;++i)
for(j=;j<=n;++j) cin>>e[i][j];
memset(f,,sizeof(f));
f[][]=;
int cur=;
for(i=;i<=n;++i){
cur^=;
memset(f[cur],,sizeof(f[cur]));
for(j=;j<(<<n);++j){
if(!f[cur^][j]) continue;
for(k=;k<=n;++k){
if(e[i][k]&& ((<<(k-))&j)==) {
f[cur][j|(<<(k-))]+=f[cur^][j];
}
}
}
/*for(j=0;j<(1<<n);++j){
cout<<j<<' '<<f[cur][j]<<endl;
}*/
}
cout<<f[cur][(<<n)-]<<endl;
}
return ;
}
spoj-ASSIGN-bitDP的更多相关文章
- [转]thinkphp 模板显示display和assign的用法
thinkphp 模板显示display和assign的用法 $this->assign('name',$value); //在 Action 类里面使用 assign 方法对模板变量赋值,无论 ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- [LeetCode] Assign Cookies 分点心
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- iOS中assign,copy,retain之间的区别以及weak和strong的区别
@property (nonatomic, assign) NSString *title; 什么是assign,copy,retain之间的区别? assign: 简单赋值,不更改索引计数(Refe ...
- 【iOS atomic、nonatomic、assign、copy、retain、weak、strong】的定义和区别详解
一.atomic与nonatomic 1.相同点 都是为对象添加get和set方法 2.不同点 atomic为get方法加了一把安全锁(及原子锁),使得方法get线程安全,执行效率慢 nonatomi ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- strong,weak, retain, assign的区别
strong,weak, retain, assign的区别 strong与weak是由ARC新引入的对象变量属性 xcode 4.2(ios sdk4.3和以下版本)和之前的版本使用的是retain ...
- iOS中assign、copy 、retain等关键字的含义
iOS中assign.copy .retain等关键字的含义 转自:http://my.oschina.net/majiage/blog/267409 assign: 简单赋值,不更改索引计数cop ...
- Objective-c的@property(atomic,nonatomic,readonly,readwrite,assign,retain,copy,getter,setter) 属性特性
assign:指定setter方法用简单的赋值,这是默认操作.你可以对标量类型(如int)使用这个属性.你可以想象一个float,它不是一个对象,所以它不能retain.copy. retain:指定 ...
- com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address: bind
在发布 web service 时报错: Endpoint.publish(publishAddress, hl7MessageReveiver); com.sun.xml.internal.ws.s ...
随机推荐
- 马尔可夫随机场(Markov random fields) 概率无向图模型 马尔科夫网(Markov network)
上面两篇博客,解释了概率有向图(贝叶斯网),和用其解释条件独立.本篇将研究马尔可夫随机场(Markov random fields),也叫无向图模型,或称为马尔科夫网(Markov network) ...
- vim文本编辑操作
文本选择操作 为了方便地选取文本块,Vim编辑器引入了可视模式(Visual Mode).要选取一段文本块,操作步骤如下: ▶ 将光标移动到要复制文本块的开始处.要注意的是 ...
- JQuery可以轻松实现数字框
如果使用JQuery,则可以轻松实现数字框. <input type="text" name="name" value="0" run ...
- 图层的使用要点(CALayer)
A,图层和路径 基本图层 CALayer 动画的主角 形状图层 CAShapeLayer 绘制不规则图形 渐变图层 CAGradientLayer 颜色渐变.阴影 复制图层 CAReplicatorL ...
- 如何下载java的jdk
1.https://www.oracle.com/index.html 2.https://www.oracle.com/downloads/index.html 3.https://www.orac ...
- redis安全设置
1. 设置监听ip为本地和内网ip bind 127.0.0.1 192.168.1.99 ## 可以是多个ip,用空格分割 2. 设置监听端口 port 16379 3. 设置密码 在配置文件中加入 ...
- MyEclipse 2014优化设置(禁用myeclipse updating indexes)
1.指定本机java环境 Windows-->preferences-->java-->Insetallel JREs 右侧 单击ADD standard VM-->Next ...
- git的应用
对git的应用 (终于第一次用会git) 根据胡东晖同学的博客(使用git推送代码到开源中国以及IDEA环境下使用git)与热心指导,自己跟着做了,虽然途中出了很多很多问题,但是好在最后还是成功了!! ...
- 用hexo在github上搭建自己的静态博客
在自己的小站上发过一次,这边就不再多发一次了,直接给链接好了: http://nerohwang.github.io/2014/02/11/simple-test/
- let与const心智模型
let 与 const 心智模型: let与const分别是变量与常量的块级声明关键字: 其主要目的是为了约束开发者编写出逻辑更加清晰,阅读性更好的代码: 它们体现了JavaScript的" ...