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 ...
随机推荐
- (转)spring mvc forward与redirect
forward 转发,如return "forward:/hello"; 浏览器的地址栏不会变,但是有视图返回来 redirect 重定向,如return "redire ...
- 深入跟踪MFC程序的执行流程
来源: http://blog.csdn.net/ljianhui/article/details/8781991 在MFC程序设计的学习过程中最令人感到难受,甚至于有时会动摇学习者信心的就是一种对于 ...
- 在MFC中使用一个单独的类实现数据在各个类之间的传递
第一步:使用VS2010创建一个基于MFC的单文档程序,然后 编译 运行 确定没有问题. 第二步:添加一个名叫CGszCommonData 类. 第三步:在应用程序类的头文件里 添加#includ ...
- SqlAlchemy 中操作数据库时session和scoped_session的区别(源码分析)
原生session: from sqlalchemy.orm import sessionmaker from sqlalchemy import create_engine from sqlalch ...
- 如何将python3.6软件的py文件打包成exe程序
在我们完成一个Python项目或一个程序时,希望将Python的py文件打包成在Windows系统下直接可以运行的exe程序.在浏览网上的资料来看,有利用pyinstaller和cx_Freeze进行 ...
- SpringCloud Config Server中{application}等占位符使用场景设置默认拉去分支
Spring Cloud Config服务器支持一个Git仓库URL,其中包含{application}和{profile}(以及{label})的占位符. 1.各个占位符所代表的含义 applica ...
- 20145316《Java程序设计》第二周学习总结
20145316<Java程序设计>第2周学习总结 教材学习内容总结 3.1.1 Java的类型 分为基本类型(Primitive type)和类类型(Class type) 基本类型: ...
- 有关string stringbuff stringbuild 的区别
string stringbuff stringbuild的执行效率: stringbuild>stringbuff>string String类是不可变类,任何对String的改变都会 ...
- NRF24L01——工作原理解读
源: NRF24L01——工作原理解读
- 自制Linux映像和发行版Robomind
通常ARM开发板厂商会提供已编译好的Linux映像供用户使用.我手上的MarS Board的厂商提供了Ubuntu映像,只是版本有点老,文件系统也比较大.之前我已经移植了较新的Linux内核,现在我想 ...