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 Tindicating 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和m,接下来n行n列输入pij,代表第i个问题放在位置j的值,求满足所有问题放在合适的位置上的值的和大于等于m的期望
,也就是求有多少种可能的组合。
shu[i] 代表用二进制表示的已经表示的数的情况,1表示已经使用,0表示没使用,具体可以看一下状压dp的简单介绍,用二进制存储状态
judge[i] 代表i的阶乘
dp[i][j] 代表将i的二进制位为1的位数的值的和为j时的个数枚举就是,
k代表已经表示了的题最后结果就是dp[ shu[n] - 1 ][m] ,不过要和judge[n]一起gcd一下
另外长记性了,写错了gcd,一直没改出来,还是用__gcd吧

  minn = min(m , l + a[j][k]); 这里如果大于m,就让他等于m,这样dp[][m]才是正确答案

 
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
using namespace std;
int a[][];
int dp[ (<<) + ][];
int shu[];
int judge[];
int minn,n,m,k; void init()
{
shu[] = ;
judge[] = ;
for(int i=;i<=;i++)
{
shu[i] = shu[i-]*;
judge[i] = judge[i-]*i;
}
return ;
}
void init2()
{
for(int i=;i<shu[n];i++)
{
for(int j=;j<=m;j++)
{
dp[i][j] = ;
}
}
dp[][] = ;
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
return ;
}
int main()
{
int t;
scanf("%d",&t);
init();
while(t--)
{
scanf("%d%d",&n,&m);
init2();
for(int i=;i<shu[n];i++)
{
k = ;
for(int j=;j<n;j++)
{
if(i&shu[j])
{
k++;
}
} for(int j=;j<n;j++)
{
if(!(i&shu[j]))
{
for(int l=;l<=m;l++)
{
minn = min(m , l + a[j][k]);
dp[i|shu[j]][minn] += dp[i][l];
}
}
}
}
int k1 = judge[n];
int k2 = dp[shu[n] - ][m];
if(!k2){
cout<<"No solution"<<endl;
}
else{
int k3 = __gcd(k1,k2);
cout<<k1/k3<<"/"<<k2/k3<<endl;
}
}
return ;
}
												

ZOJ - 3777(状压dp)的更多相关文章

  1. Problem Arrangement ZOJ - 3777(状压dp + 期望)

    ZOJ - 3777 就是一个入门状压dp期望 dp[i][j] 当前状态为i,分数为j时的情况数然后看代码 有注释 #include <iostream> #include <cs ...

  2. ZOJ 3306 状压dp

    转自:http://blog.csdn.net/a497406594/article/details/38442893 Kill the Monsters Time Limit: 7 Seconds ...

  3. Most Powerful(ZOJ 3471状压dp)

    题意:n个原子,两两相撞其中一个消失,产生能量,给出任意两原子相撞能产生的能量,求能产生的最大能量. 分析:dp[i]表示情况为i时产生的最大能量 /*#include <map> #in ...

  4. Survival(ZOJ 2297状压dp)

    题意:有n个怪,已知杀死第i个怪耗费的血和杀死怪恢复的血,和杀死boss耗的血,血量不能超过100,若过程中血小于0,则失败,问 是否能杀死boss(boss最后出现). 分析:就是求杀死n个怪后剩余 ...

  5. zoj 3812 状压dp

    转载:http://blog.csdn.net/qian99/article/details/39138329 题意:给出n个物品,每个物品有两种属性Wi,Ti,有q组查询,每组查询要求在n个物品中选 ...

  6. Long Dominoes(ZOJ 2563状压dp)

    题意:n*m方格用1*3的方格填充(不能重叠)求有多少种填充方法 分析:先想状态,但想来想去就是觉得不能覆盖所有情况,隔了一天,看看题解,原来要用三进制 0 表示横着放或竖放的最后一行,1表示竖放的中 ...

  7. Travel(HDU 4284状压dp)

    题意:给n个城市m条路的网图,pp在城市1有一定的钱,想游览这n个城市(包括1),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...

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

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

  9. ZOJ 3723 (浙大月赛)状压DP

    A了一整天~~~终于搞掉了. 真是血都A出来了. 题目意思很清楚,肯定是状压DP. 我们可以联系一下POJ 1185  炮兵阵地,经典的状压DP. 两道题的区别就在于,这道题的攻击是可以被X挡住的,而 ...

随机推荐

  1. C++的异常捕获

    听课笔记: #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; void fun() { ;// ...

  2. JavaScript秘密

    对象 对象使用和属性 JavaScript 中所有变量都可以当作对象使用,除了两个例外 null 和 undefined. false.toString(); // 'false' [1, 2, 3] ...

  3. Java_数据交换_Gson_00_资源帖

    1.Gson将字符串转换成JsonObject和JsonArray 2.Gson 解析教程 3.Gson全解析(上)-Gson基础

  4. gradle_学习_00_资源贴

    一.官方资料 1.Gradle User Guide 中文版 二.精选资料 1.Gradle学习系列之一——Gradle快速入门 2.Gradle教程

  5. 【leetcode刷题笔记】Flatten Binary Tree to Linked List

    Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...

  6. python 3 serial module install

    /************************************************************************* * python 3 serial module ...

  7. FFmpeg内存操作(三)内存转码器

    相关博客列表 : FFMPEG内存操作(一) avio_reading.c 回调读取数据到内存解析 FFMPEG内存操作(二)从内存中读取数及数据格式的转换 FFmpeg内存操作(三)内存转码器 本文 ...

  8. BZOJ4317: Atm的树+2051+2117

    BZOJ4317: Atm的树+2051+2117 https://lydsy.com/JudgeOnline/problem.php?id=4317 分析: 二分答案之后就变成震波那道题了. 冷静一 ...

  9. Access中一句查询代码实现Excel数据导入导出

    摘 要:用一句查询代码,写到vba中实现Excel数据导入导出,也可把引号中的SQL语句直接放到查询分析器中执行正 文: 导入数据(导入数据时第一行必须是字段名): DoCmd.RunSQL &quo ...

  10. windows拾遗

    Files has invalid value "<<<<<<< .mine". Illegal characters in path.在 ...