zoj 3777 Problem Arrangement

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5264

题意:给出n道题目以及每一道题目不同时间做的兴趣值,让你求出所有做题顺序中兴趣值大于等于m的比例。用一个分数表示。

状压dp。 枚举每一个状态,用二进制表示。dp[i][j]表示第i个题目,兴趣值为j的个数。

转移方程 dp[i|(1<<j)][k+a[num][j]]+=dp[i][k];兴趣值大于m的为 dp[1|(1<<j)][m]+=dp[i][k];

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define LL long long
 5 using namespace std;
 6
 7 int t,n,m;
 8 int p[15][15];
 9 int dp[1<<13][1000];
10 int f[10000];
11
12 LL gcd(LL a,LL b)
13 {
14     return b==0?a:gcd(b,a%b);
15 }
16
17 int main()
18 {
19     scanf("%d",&t);
20     f[1]=1;
21     for(int i=2; i<=12; i++)
22     {
23         f[i]=f[i-1]*i;
24     }
25     while(t--)
26     {
27         scanf("%d%d",&n,&m);
28         memset(dp,0,sizeof(dp));
29         for(int i=0; i<n; i++)
30         {
31             for(int j=0; j<n; j++)
32             {
33                 scanf("%d",&p[i][j]);
34             }
35         }
36         dp[0][0]=1;
37         for(int i=0; i<=(1<<n); i++)
38         {
39             int num=0;
40             for(int j=0; j<n; j++)
41             {
42                 if(i&(1<<j)) num++;
43             }
44             for(int j=0; j<n; j++)
45             {
46                 if(i&(1<<j)) continue;
47                 for(int k=0; k<=m; k++)
48                 {
49                     if(k+p[num][j]>=m)
50                     {
51                         dp[i|(1<<j)][m]+=dp[i][k];
52                     }
53                     else
54                     {
55                         dp[i|(1<<j)][k+p[num][j]]+=dp[i][k];
56                     }
57                 }
58             }
59         }
60         if(dp[(1<<n)-1][m]==0)
61         {
62             printf("No solution\n");
63         }
64         else
65         {
66             int g=gcd(f[n],dp[(1<<n)-1][m]);
67             printf("%d/%d\n",f[n]/g,dp[(1<<n)-1][m]/g);
68         }
69     }
70     return 0;
71 }

时间: 2024-08-13 20:48:11

zoj 3777 Problem Arrangement的相关文章

ZOJ 3777 Problem Arrangement(状压DP)

题目链接 : http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5264 //今年省赛的题目,比赛的时候知道是状压却一直没搞出,直到最后.虽然赛后知道做法,也一直没做的,最近想不开就来做了 - -, 顺便用了下快速枚举k-子集. 恩, 做法么就是开dp[i][j] i已经选过了的题目的一个集合,j表示的是获得了j分,然后就可以直接做了..(但是好像说会T或者卡空间,我的做法是快速枚举k-子集,这个东西可以看下watashi翻译的

B - Problem Arrangement ZOJ - 3777

Problem Arrangement ZOJ - 3777 题目大意:有n道题,第i道题第j个做可以获得Pij的兴趣值,问至少得到m兴趣值的数学期望是多少,如果没有的话就输出No solution. 数学期望很好求,求出符合的方案数与总方案之比就是概率,概率的倒数就是期望.问题在于怎么安排这些题目的做题顺序,如果直接暴力的话,有12!种情况,铁定超时,所以我们可以转换成dp的思想,总共就是12道题,也就212-1种状态,我们枚举每个状态得多少分时的方案数,最终符合的方案数就是dp[212-1]

2014 Super Training #4 B Problem Arrangement

原题:ZOJ 3777  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 题意:给每个题目安排在每个位置的value.有一个程序随机选择安排的顺序,总的value值大于等于m时,就可以接受这个安排.问能够获得一次满足条件的安排的期望次数. 这题不会做,看网上是用状态压缩DP做的. 定义: dp[i][j]为选取了前i行,趣味和为j的方案种数. 由于程序是每次随机选择一个排列,每次的选择之间不影响,而且每次选中的概

ZOJ 3959: Problem Preparation

Problem Preparation ///@author Sycamore, ZJNU ///@date 4/22/2017 #include <iostream> #include <sstream> #include <iomanip> #include <cmath> #include <string> #include <algorithm> #include <numeric> #include <fu

zoj Abs Problem

Abs Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Alice and Bob is playing a game, and this time the game is all about the absolute value! Alice has N different positive integers, and each number is not greater than N.

ZOJ-3777 Problem Arrangement(状态压缩DP)

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int dp[1<<13][510],map[13][13];int m,n;int gcd(long long a,long long b){ if(b!=0) return gcd(b,a%b); return a;}int main(){ int T; scanf("%d",&T

2014浙江省赛

ZOJ 3777 Problem Arrangement 状态压缩DP,种数DP,dp[s][m]代表当前被占位置的集合分数为m的方案数,父母是总数n!,记忆化搜索好写 by fd ZOJ 3785 What day is that day? 等比数列,逆元,快速幂,当然可以暴力找循环节,有mod肯定有循环节,因为x^y%7 等价于(x%7)^y,所以可以分成6个第比数列,如下 1^1,2^2,3^3,4^4,5^5,6^6,0^7 1^8,2^9,3^10,4^11,5^12,6^13,0,^

HDU 3788 zoj问题

ZOJ问题 Problem Description 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. 是否AC的规则如下:1. zoj能AC:2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空:3. 若azbjc 能AC,则azbojac也能AC,其中a,b,c为N个'o'或者为空: Input 输入包含多组测试用例,每行有一个只包含'z','o','j'三种字符的字符串,字符串长度小于等于1000: Output 对于给定的字符串,如果能AC

n!在k进制下的后缀0

问n! 转化成k进制后的位数和尾数的0的个数.[UVA 10061 How many zeros and how many digits?] Given a decimal integer number you will have to find out how many trailing zeros will be there in its factorial in a given number system and also you will have to find how many di