ZOJ 3777-Problem Arrangement(状压DP)
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward is going to arrange the order of the problems. As we know, the arrangement will have a great effect on the result of the contest. For example, it will take more time to finish the first problem if the easiest problem hides in the middle of the problem list.
There are N problems in the contest. Certainly, it's not interesting if the problems are sorted in the order of increasing difficulty. Edward decides to arrange the problems in a different way. After a careful study, he found out that the i-th problem placed in the j-th position will add Pij points of "interesting value" to the contest.
Edward wrote a program which can generate a random permutation of the problems. If the total interesting value of a permutation is larger than or equal to M points, the permutation is acceptable. Edward wants to know the expected times of generation needed to obtain the first acceptable permutation.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains two integers N (1 <= N <= 12) and M (1 <= M <= 500).
The next N lines, each line contains N integers. The j-th integer in the i-th line is Pij (0 <= Pij <= 100).
Output
For each test case, output the expected times in the form of irreducible fraction. An irreducible fraction is a fraction in which the numerator and denominator are positive integers and have no other common divisors than 1. If it is impossible to get an acceptable permutation, output "No solution" instead.
Sample Input
2
3 10
2 4 1
3 2 2
4 5 3
2 6
1 3
2 4
Sample Output
3/1
No solution
#include <bits/stdc++.h>
using namespace std;
int t;
int n,m;
int a[][];
int dp[(<<)][];//表示i种状态,获取j的快乐度的方案数
int f[];
void init(){
memset(dp,,sizeof dp);
}
int main(){
// freopen("in.txt","r",stdin);
f[]=;
for(int i=;i<=;i++){
f[i]=f[i-]*i;
}
scanf("%d",&t);
while(t--){
init();
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&a[i][j]);
}
}
dp[][]=;
int tol=(<<n);
for(int i=;i<=tol;i++){//枚举状态
int tmp=;
for(int j=;j<=n;j++){
if( ( i&(<<(j-)) ) )
tmp++;
}
for(int j=;j<=n;j++){
if(( i&(<<(j-)) )==)
for(int k=;k<=m;k++){
if(k+a[tmp+][j]>=m){
dp[i+(<<(j-))][m]+=dp[i][k];
}else{
dp[i+(<<(j-))][k+a[tmp+][j]]+=dp[i][k];
}
}
}
}
if(dp[tol-][m]==){
puts("No solution");
}else{
int res=__gcd(f[n],dp[tol-][m]);
printf("%d/%d\n",f[n]/res,dp[tol-][m]/res);
}
}
return ;
}
ZOJ 3777-Problem Arrangement(状压DP)的更多相关文章
- ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds Me ...
- zoj3777 Problem Arrangement(状压dp,思路赞)
The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...
- ZOJ 3777 B - Problem Arrangement 状压DP
LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 题意:有N(\( N <= 12 \))道题,排顺序 ...
- zoj 3777 Problem Arrangement(壮压+背包)
Problem Arrangement Time Limit: 2 Seconds Memory Limit: 65536 KB The 11th Zhejiang Provincial C ...
- 2014 Super Training #4 B Problem Arrangement --状压DP
原题:ZOJ 3777 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 题意:给每个题目安排在每个位置的value ...
- FZU - 2218 Simple String Problem(状压dp)
Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...
- zoj 3777 Problem Arrangement
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5264 题意:给出n道题目以及每一道题目不同时间做的兴趣值,让你求出所有做题顺序 ...
- ZOJ 3723 (浙大月赛)状压DP
A了一整天~~~终于搞掉了. 真是血都A出来了. 题目意思很清楚,肯定是状压DP. 我们可以联系一下POJ 1185 炮兵阵地,经典的状压DP. 两道题的区别就在于,这道题的攻击是可以被X挡住的,而 ...
- ACM学习历程—ZOJ 3777 Problem Arrangement(递推 && 状压)
Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...
随机推荐
- css预处理器less和scss之sass介绍(二)
本来打算整理jQuery Mobile来着,但是没有研究明白,所以接着上个周的继续介绍... [scss中的基础语法] 1.scss中的变量 ①声明变量:$变量名:变量值 $width:100px ...
- BZOJ2748_音量调节_KEY
[HAOI2012]音量调节 Time Limit: 3 Sec Memory Limit: 128 MB Description 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以 ...
- Spring 3.x 读书笔记
第一:如果使用BeanFactory作为Spring Bean的工厂类,则所有的bean都是在第一次使用该Bean的时候实例化 第二:如果使用ApplicationContext作为Spring Be ...
- babel的使用详解
由于es6的很多特性在旧的浏览器下支持不好,我们在使用的时候需要将其转化为es5,下面介绍babel解析器的使用 一:独立使用babel的方法 1.本地安装babel-cli npm install ...
- Linux入门之常用命令(3)
df 查看硬盘总容量.已用容量和inode [-ikm] du 查看文件已用容量,显示所有文件 每块硬盘最多四个分区. fdisk [-l] [设备名称] 硬盘分区工具 (-l 显示这张硬盘的分区) ...
- Lowbit Sum 规律
Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitSt ...
- Thirft框架快速入门
Thrift介绍1.什么是thrift?thrift早期由facebook内部团队开发,主要用于实现跨语言间的方法调用,属于远程方法调用的一种,后开源纳入apache中,成为了apache thrif ...
- Python实战之dict简单练习
['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__forma ...
- Python自学笔记-sorted()函数(来自廖雪峰的官网Python3)
感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 排序算法 排序 ...
- sublime text注册码(秘钥)
—– BEGIN LICENSE —– TwitterInc 200 User License EA7E-890007 1D77F72E 390CDD93 4DCBA022 FAF60790 61AA ...