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. 一个简单、易用的Python命令行(terminal)进度条库

    eprogress 是一个简单.易用的基于Python3的命令行(terminal)进度条库,可以自由选择使用单行显示.多行显示进度条或转圈加载方式,也可以混合使用. 示例 单行进度条 多行进度条 圆 ...

  2. Selenium自动化初级/中级网络授课班招生

    近期学习selenium和appium的测试人员越来越多,应广大刚接触UI自动化以及对selenium想要更深入了解的测试人员的要求,特请一位资深测试架构师为我们开课讲解selenium,以及如何设计 ...

  3. 仿PC版微信的练手项目(可实时通讯)

    仿PC版微信的DEMO 本项目是由一个仿PC版微信的vue前端项目,和一个使用leancloud进行数据存储的.提供WebSocket的node后端项目构成. 本项目使用的技术栈:vue + vue- ...

  4. 快学 Scala 入门 3 部曲

    1 基础 1.1 Scala 解释器 REPL - 交互式解释器环境 R(read).E(evaluate).P(print).L(loop) 输入值,交互式解释器会读取输入内容并对它求值,再返回结果 ...

  5. 微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)

    第一步:准备 1.智能手机微信客户端或微信电脑版 2.注册微信公众平台 https://mp.weixin.qq.com 3.注册新浪账号 http://www.sinacloud.com 4.拥有一 ...

  6. 有时在UIWindow上添加遮罩层不成功的原因

    程序启动后,初始化window,初始化controller,加载试图,这三个方法的顺序是嵌套的 类似于: - (id) initWindow {[self initController];} 而我在i ...

  7. Open-Falcon第二步安装绘图组件Transfer(小米开源互联网企业级监控系统)

    ----安装绘图组件---- 安装Transfer transfer默认监听在:8433端口上,agent会通过jsonrpc的方式来push数据上来. cd /usr/local/open-falc ...

  8. Git异常情况汇总

    本篇博客总结下Git使用情况中遇到的异常情况并给出解决方案,关于Git的常用命令请移步我的另一篇博客<Git常用命令> 异常情况如下: 1.git远程删除分支后,本地git branch ...

  9. 一个想法照进现实-《IT连》创业项目:聊聊IT连App是如何思考解决IT人员单身问题的

    前言: 根据最早我编写的IT联盟社区众筹计划书的思路方向:社交->资讯=>评级=>培训. 现在在实现第一个阶段中,而且这个阶段可能会走很久. 今天开文,主要是讲述一下,现在的版本为什 ...

  10. 【有意思的BUG】需要停止的进程

    用户操作的目的:将某网站的歌曲分享到朋友圈 用户遇到的问题:在朋友圈内,有2个入口可以播放该第三方的歌曲.但是这两个入口可以同时播放,音乐重叠了. 操作步骤: [1] 将歌曲分享到朋友圈 [2] 在朋 ...