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. 创建 CSS3 下拉菜单

    1. [图片] 菜单效果 2. [代码]menu.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ...

  2. Luogu P1463 [HAOI2007]反素数ant:数学 + dfs【反素数】

    题目链接:https://www.luogu.org/problemnew/show/P1463 题意: 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4. 如果某个正整数x ...

  3. linux没有eth0

    1.创建ifcfg-eth0 touch /etc/sysconfig/network-scripts/ifcfg-eth0 2.配置ifcfg-eth0 DEVICE=eth0 HWADDR=:0c ...

  4. php 代码中的箭头“ ->”与“=>”是什么意思?

    类是一个复杂数据类型,这个类型的数据主要有属性.方法两种东西. 属性其实是一些变量,可以存放数据,存放的数据可以是整数.字符串,也可以是数组,甚至是类. 方法实际上是一些函数,用来完成某些功能. 引用 ...

  5. ATL实现COM组件

    参考文献:https://blog.csdn.net/Marcus2006/article/details/41978799 ATL实现COM组件比较简单,关键是在程序中如何调用该组件. vs2010 ...

  6. codeforces 598C C. Nearest vectors(极角排序)

    题目链接: C. Nearest vectors time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. hdu-5635 LCP Array

    LCP Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  8. bzoj 4771: 七彩树 树链的并+可持久化线段树

    题目大意: 给定一颗树,询问树中某个点x的子树中与其距离不超过d的所有点中本质不同的颜色数 强制在线 题解: 一下午终于把这道题叉掉了. 写了三个算法,前两个都是错的,后一个是%的网上大爷们的题解. ...

  9. Poj 2328 Guessing Game(猜数字游戏)

    一.题目大意 两个小盆友玩猜数字游戏,一个小盆友心里想着1~10中的一个数字,另一个小盆友猜.如果猜的数字比实际的大,则告诉他"too high",小则"too low& ...

  10. NetScaler VPX在Azure上的部署(二)

    本文是Citrix的工程师协助完成.主要是Citrix的VPX的配置. 导入License   进入NetScaler 中点击管理许可   导入后将有提示,请确认重启.   配置Azure HA 由于 ...