题意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a3-+ai,问满足Si<=p的i的最大值的期望.(p<=50) 这道题在网上有一些不同的做法,O(n^3)或O(n^4)都可以通过,这里整合一下,标上出处,其实我只写了自己YY的那一种,叫我搬运工 1.期望的线性性,讨论每个数对i的贡献.O(n^4) 自己YY的,不知道以前有没有人也写过这种方法. 如果ai满足Si<=p,那么ai就对答案有1 的贡献,因此我们算出每个数ai满足Si<…
B. Maxim and Restaurant time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters. Maxim has…
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a3-+ai,问满足Si<=p的i的最大值的期望.(p<=50) (大意来自于http://www.cnblogs.com/liu-runda/p/6253569.html) 我们知道,全排列其实等价于我们一个一个地等概率地向一个序列里面插入数值 所以我们可以这么看这道题: 现在有n个数,有n个盒子…
什么什么期望的,不会! (题解http://blog.sina.com.cn/s/blog_140e100580102wj4e.html(看不懂)) #include<bits/stdc++.h> #define LL long long #define LD long double #define N 100005 using namespace std; inline int ra() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-'; ch…
题目链接 第一种解法是$O(n^3*p)$的:f[i][j][k]表示前i个人进j个人长度为k有几种方案(排列固定为123..n时).$f[i][j][k]=f[i-1][j][k]+f[i-1][j-1][k-a[i]]$最外层枚举t表示被卡的那个人.i=t时不加上f[i-1][j-1][k-a[i]].$ans={{(\sum f[n][j][k]*j*j!*(n-1-j)!)+(\sum f[n][n][k]*n)}}/(n!)$. 可以看看这篇题解 #include<cstdio> #…
题目链接 想了挺久,枚举每一件物品,当做关键物品,假设再加这一件物品,就>=c了,把剩下的物品背一下包,dp[i][j]表示i个物品可以组成重量j的个数. 这样就可以知道前面放i件,后边肯定放n-i-1件,乱搞搞,算double,边乘边算保证不要越界.最后注意,LL和sum <= c的时候情况. #include <iostream> #include <cstdio> #include <cstring> #include <vector> #…
整数划分问题是一个锻炼组合数学,递归以及动态规划很好的例子,虽然问题看似简单,但是其中玄机万千,有人转化成为背包问题,有人用生成函数解,有人以此作为企业面试题目,可见这种问题的认可度还是很高的. 整数划分问题可以出现很多变种问题: 1. 将n划分成若干正整数之和的划分数.(原题) 2. 将n划分成k个正整数之和的划分数. 3. 将n划分成最大数不超过k的划分数. 4. 将n划分成若干奇正整数之和的划分数. 5. 将n划分成若干不同整数之和的划分数...... 第2,3,5的Code在北大研究生推…
A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of peopl…
题目链接:http://codeforces.com/contest/854/problem/B 题意: 有n栋房子从1到n排成一排,有k栋房子已经被售出. 现在你要买一栋“好房子”. 一栋房子是“好房子”的要求:(1)没被售出 (2)至少有一栋已售出的房子与他相邻(有邻居) 问你可能的好房子总数量的最小值和最大值. 题解: 贪心. 最小值: 从第1栋房子开始紧挨着往右共k栋全都售出了,好房子只有一栋就是第k栋楼的右边一栋. 特判:k == 0 || n == k:没有好房子,输出0. 最大值:…
题目描述: Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he…