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 题目大意:给出n个物品,将他们排列,第i个物品放在j位置可获得p[i][j]的价值,求总排列数除以总价值大于m的排列数,结果以最简分数的形式输出。 思路: 递推题目,f[i][j][k]表示按顺序取,当前取到第i个物品时,状态为j,总价值为j的时候的方案数。递推方程,f[i+1][j+(2<<(t-1))][k+a[i,t]]+=f[i][j][k]。
 /*
* Author: Joshua
* Created Time: 2014/5/17 14:31:42
* File Name: b.cpp
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<ctime>
#include<utility>
#define M0(x) memset(x, 0, sizeof(x))
#define MP make_pair
#define Fi first
#define Se second
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define red(i, a, b) for (int i = (a); i >= (b); --i)
#define PB push_back
#define Inf 0x3fffffff
#define eps 1e-8 #define b(i) (1<<i)
typedef long long LL;
using namespace std; int f[][b()][],p[];
int a[][];
int n,m; int gcd(int aa,int bb)
{
if (bb==) return aa;
else return gcd(bb,aa%bb);
} int main()
{
int tt;
int cc;
scanf("%d",&tt);
while (tt>)
{
tt--;
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
scanf("%d",&a[i][j]);
M0(f);
int temp;
int gg,vv;
f[][][]=;
gg=;
vv=;
for (int i=;i<n;i++)
{
gg=-gg;
vv=-vv;
M0(f[gg]);
for (int j=;j<=(<<n)-;j++)
{
cc=;
for (int t=;t<=n;t++)
if ((j & b(t-)) > ) cc++;
if (cc!=i) continue;
for (int t=;t<=n;t++)
if ((b(t-) & j)==)
for (int k=;k<=m;k++)
if (f[vv][j][k]>)
{
temp=k+a[i+][t];
if (temp>m) temp=m;
f[gg][ j|b(t-) ][temp]+=f[vv][j][k];
}
}
}
int sum=f[gg][b(n)-][m];
if (sum>)
{
int ss=;
for (int i=;i<=n;i++)
ss*=i;
int gc=gcd(sum,ss);
printf("%d/%d\n",ss/gc,sum/gc);
}
else
{
printf("No solution\n");
}
}
return ;
}

因为空间不够所以采用滚动数组,然后超时了所以要尽量把无效状态判掉。时间看起来是(2^(2n)*m*n),判无效状态后为(2^n*m*n)。其实我这是正着推,看同学反着推好像更好写且不用滚动数组和判无效,果然我还是写得太丑了。

zoj3777 Problem Arrangement的更多相关文章

  1. ACM学习历程—ZOJ3777 Problem Arrangement(递推 && 状压)

    Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...

  2. zoj3777 Problem Arrangement(状压dp,思路赞)

    The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...

  3. B - Problem Arrangement ZOJ - 3777

    Problem Arrangement ZOJ - 3777 题目大意:有n道题,第i道题第j个做可以获得Pij的兴趣值,问至少得到m兴趣值的数学期望是多少,如果没有的话就输出No solution. ...

  4. zoj 3777 Problem Arrangement(壮压+背包)

    Problem Arrangement Time Limit: 2 Seconds      Memory Limit: 65536 KB The 11th Zhejiang Provincial C ...

  5. ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds      Me ...

  6. ACM学习历程—ZOJ 3777 Problem Arrangement(递推 && 状压)

    Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...

  7. 2014 Super Training #4 B Problem Arrangement --状压DP

    原题:ZOJ 3777  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 题意:给每个题目安排在每个位置的value ...

  8. zoj 3777 Problem Arrangement

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5264 题意:给出n道题目以及每一道题目不同时间做的兴趣值,让你求出所有做题顺序 ...

  9. ZOJ 3777 B - Problem Arrangement 状压DP

    LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 题意:有N(\( N <= 12 \))道题,排顺序 ...

随机推荐

  1. Excel无法vlookup事件

    最近由于工作关系,深入的用了一阵excel,并遭遇和处理了一系列关于excel数据的问题. 其中最有趣的一个,就是一个无法vlookup的问题. 问题记录如下: excel中直接打开csv文件,看到类 ...

  2. ES6正则表达式扩展

    前面的话 正则表达式是javascript操作字符串的一个重要组成部分,但在以往的版本中并未有太多改变.然而,在ES6中,随着字符串操作的变更, ES6也对正则表达式进行了一些更新.本文将详细介绍ES ...

  3. mysql中csv文件的导入导出

    导出例子: select *from testinto outfile 'D:test.csv'fields terminated by ',' optionally enclosed by '&qu ...

  4. Redola.Rpc 集成 Consul 服务发现

    Redola.Rpc 解决了什么问题? Redola.Rpc 是一个使用 C# 开发的 RPC 框架,代码开源在 GitHub 上.目前版本仅支持 .NET Framework 4.6 以上版本,未来 ...

  5. Spring依赖注入的简化配置

    一, 很久很久以前, 当我们不用@Autowire注解时, 依赖注入要么通过setter方法, 要么通过构造方法; 需要在配置文件里配置一大堆property-ref.......... 二, 若使用 ...

  6. 一种轻便且灵活的js模板的思路

    一种轻便且灵活的js模板的思路 项目地址:https://github.com/j20041426/template 思路背景 在Vue.React.Angular等大前端框架异军突起的今天,写前端时 ...

  7. bzoj 3594: [Scoi2014]方伯伯的玉米田

    3594: [Scoi2014]方伯伯的玉米田 Time Limit: 60 Sec  Memory Limit: 128 MB Submit: 1399  Solved: 627 [Submit][ ...

  8. Redis-误操作尝试恢复

    如果不小心使用了flushall把全部数据清楚怎么办 127.0.0.1:6379> set site www.google.com OK 127.0.0.1:6379> set addr ...

  9. svn本地目录结构for window

    演示内容: 使用svn目录结构来进行备份正式版和修复版本,最终合并修复版本.主干上的版本. 使用工具: visualSVN server 服务器软件工具 TortoiseSVN客户端工具 1.服务器的 ...

  10. React Native 系列(四) -- 布局

    前言 本系列是基于React Native版本号0.44.3写的.RN支持CSS中的布局属性,因此可以使用CSS布局属性,这里就不详细地讲解了,这篇文章的重点主要是讲述一下RN中的Flex布局. CS ...