zoj3777 Problem Arrangement
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的更多相关文章
- ACM学习历程—ZOJ3777 Problem Arrangement(递推 && 状压)
Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...
- zoj3777 Problem Arrangement(状压dp,思路赞)
The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...
- B - Problem Arrangement ZOJ - 3777
Problem Arrangement ZOJ - 3777 题目大意:有n道题,第i道题第j个做可以获得Pij的兴趣值,问至少得到m兴趣值的数学期望是多少,如果没有的话就输出No solution. ...
- zoj 3777 Problem Arrangement(壮压+背包)
Problem Arrangement Time Limit: 2 Seconds Memory Limit: 65536 KB The 11th Zhejiang Provincial C ...
- ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds Me ...
- ACM学习历程—ZOJ 3777 Problem Arrangement(递推 && 状压)
Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...
- 2014 Super Training #4 B Problem Arrangement --状压DP
原题:ZOJ 3777 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 题意:给每个题目安排在每个位置的value ...
- zoj 3777 Problem Arrangement
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5264 题意:给出n道题目以及每一道题目不同时间做的兴趣值,让你求出所有做题顺序 ...
- ZOJ 3777 B - Problem Arrangement 状压DP
LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 题意:有N(\( N <= 12 \))道题,排顺序 ...
随机推荐
- “玲珑杯”ACM比赛 Round #12 (D) 【矩阵快速幂的时间优化】
//首先,感谢Q巨 题目链接 定义状态向量b[6] b[0]:三面临红色的蓝色三角形个数 b[1]:两面临红色且一面临空的蓝色三角形个数 b[2]:一面临红色且两面临空的蓝色三角形个数 b[3]:三面 ...
- javascript实现朴素贝叶斯分类与决策树ID3分类
今年毕业时的毕设是有关大数据及机器学习的题目.因为那个时间已经步入前端的行业自然选择使用JavaScript来实现其中具体的算法.虽然JavaScript不是做大数据处理的最佳语言,相比还没有优势,但 ...
- FCKEditor在jsp页面中的配置方法
大家在使用博客园或者是在网站上面发表一些东西的时候,往往会发现,输入文字的不是一个简单的文本框,而是一个类似于word的在线编辑环境.这个插件叫FCKEditor,使用这个插件要进行一定程度的配置,下 ...
- web组件工具之获取表单数据:webUtils
本文需要的架包:commons-beanutils-1.8.3.jar.commons-logging-1.1.3.jar.servlet-api.jar. 本文共分为五部分:1)封装通用工具类:从表 ...
- vue-项目入门
初入前端的新人在碰到vue.js后,去过官网,估计粗略的看下api文档以后会以为vue的安装只是把那串js代码直接粘贴复制到文档即可,虽然这样是可以,但那在项目中并不合适. 项目中的vue引入(配制安 ...
- unable to create …
问题描述: 在新建Android Application时会出现unable to create the selected property page 解决方法: 将用户PATH路径中的jdk路径放到 ...
- ASP.NET 导出excel文件出现乱码的解决办法
string html =TABLE ;//<table>标签,可以是多张表string modified = Regex.Replace(html, "<table &g ...
- Akka(16): 持久化模式:PersistentFSM-可以自动修复的状态机器
前面我们讨论过FSM,一种专门为维护内部状态而设计的Actor,它的特点是一套特殊的DSL能很方便地进行状态转换.FSM的状态转换模式特别适合对应现实中的业务流程,因为它那套DSL可以更形象的描述业务 ...
- 今天聊一聊nuxt.js(上)
背景 近期在做内部系统的重构,从一线业务彻底的重构,经过充分的考虑我们准备把这个项目打造成前台业务的试验站,比如ssr和一些其他的前沿技术的探索,积累充分的经验后待合适的契机应用到C端的项目中. 既然 ...
- 从入门到放弃,.net构建博客系统(一):系统构建篇
demo:http://tonyblogs.top/ Git源码:https://github.com/Halifa/TonyBlogs 项目采用的技术有:asp.net mvc4 + autofac ...