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. Effective Objective-C 2.0 Tips 总结 Chapter 3 & Chapter 4

    Chapter 3 接口与 API 设计 Tips 15 使用前缀避免明明空间冲突 Objective-C 没有命名空间,所以我们在起名时要设法避免命名冲突 避免命名冲突的方法就是使用前缀 应用中的所 ...

  2. 第2章 rsync(二):inotify+rsync详细说明和sersync

    本文目录: inotify+rsync 1.1 安装inotify-tools 1.2 inotifywait命令以及事件分析 1.3 inotify应该装在哪里 1.4 inotify+rsync示 ...

  3. 富文本编辑器UEditor自定义工具栏(二、插入图片、音频、视频个性化功能按钮和弹层及自定义分页符)

    导读:本篇将简单探讨插入图片.音频.视频的功能按钮实现方式 传送门:富文本编辑器UEditor自定义工具栏(一.基础配置与字体.背景色.行间距.超链接实现) 一.效果图 1.UEditor自定义工具栏 ...

  4. (转)log4j(三)——如何控制不同级别的日志信息的输出?

    一:测试环境与log4j(一)——为什么要使用log4j?一样,这里不再重述 1 老规矩,先来个栗子,然后再聊聊感受 package test.log4j.test3; import org.apac ...

  5. (转)OGNL表达式介绍

    OGNL是Object-Graph Navigation Language的缩写,它是一种功能强大的表达式语言(Expression Language,简称为EL),通过它简单一致的表达式语法,可以存 ...

  6. 【整理】01. jQuery.Form.js 用法分析

    前言: 为什么使用JQuery.From.js,因为原生<form>表单没有回调函数,不过可以通过jquery-form.js这个插件来实现回调函数. jQuery.form.js是一个f ...

  7. Redux源码分析之combineReducers

    Redux源码分析之基本概念 Redux源码分析之createStore Redux源码分析之bindActionCreators Redux源码分析之combineReducers Redux源码分 ...

  8. POJ 2386 Lake Counting (简单深搜)

    Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...

  9. C# 将数据表导出到Excel通用方法

    DataGrid dg = new DataGrid(); dg.DataSource = dt; dg.DataBind(); Response.Clear(); Response.Buffer = ...

  10. html5 textarea 文本框根据输入内容自适应高度

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...