A - 容斥原理(CodeForces - 451E)

二进制状态压缩暴力枚举哪几个花选的个数超过了总个数,卢卡斯定理求组合数,容斥原理求答案

可以先把每个花的数量当成无限个,这样就是一个多重集的组合数$ans=C_{n+m-1}^{n-1}$

所以要减去有一种花超过花的数量的情况,加上有两种花超过花的数量的情况,减去有三种花超过花的数量的情况...

最后$ans=C_{n+m-1}^{n-1}-\sum_{i=1}^{n}C_{n+m-a_{i}-2}^{n-1}+\sum_{i=1}^{n}C_{n+m-a_{i}-a_{j}-3}^{n-1}-...+(-1)^{n}C_{n+m-\sum a_{i} -(n+1)}^{n-1}$

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. const int N = ;
  8. const int MOD = ;
  9.  
  10. ll n, s, f[N];
  11.  
  12. ll qPow(ll a, ll k, ll p)
  13. {
  14. ll ans = ;
  15. while (k) {
  16. if (k & ) ans = (ans * a) % p;
  17. a = (a * a) % p, k /= ;
  18. }
  19. return ans;
  20. }
  21.  
  22. ll C(ll a, ll b, ll p)
  23. {
  24. if (a < b) return ;
  25. if (b > a - b) b = a - b;
  26. ll up = , down = ;
  27. for (ll i = ; i < b; i++) {
  28. up = up * (a - i) % p;
  29. down = down * (i + ) % p;
  30. }
  31. return up * qPow(down, p - , p) % p;
  32. }
  33.  
  34. ll Lucas(ll a, ll b, ll p) {
  35. if (b == ) return ;
  36. return C(a%p, b%p, p) * Lucas(a / p, b / p, p) % p;
  37. }
  38.  
  39. ll solve()
  40. {
  41. ll res = ;
  42. for (int i = ; i < ( << n); i++) {
  43. ll t = s, sign = ;
  44. for (int j = ; j < n; j++) {
  45. if (i & ( << j)) t -= (f[j] + ), sign *= -;
  46. }
  47. if (t < ) continue;
  48. res = (res + sign * Lucas(t + n - , n - , MOD)) % MOD;
  49. }
  50. return (res + MOD) % MOD;
  51. }
  52.  
  53. int main()
  54. {
  55. cin >> n >> s;
  56. for (int i = ; i < n; i++) cin >> f[i];
  57. cout << solve() << endl;
  58. return ;
  59. }

A - 容斥原理(CodeForces - 451E)

B - 危险的组合(Critical Mass,UVa580)

设答案为$f(n)$,分两种情况:

  • 当加入第$n$个元素时组成三个放在一起的U,那么第$n - 1,n - 2$都为U,第$n - 3$为L,保证前$n-4$个元素不会出现三个U放在一起,所以此时有$2^{n-4} - f(n - 4)$种可能
  • 当前$n - 1$个元素已经形成了三个放在一起的U,那么第$n$个是U还是L都能形成三个放在一起的U,所以此时有$2 * f(n - 1)$中可能

得出递推关系式$f(n)=2 * f(n - 1) + 2^{n-4} - f(n - 4)$

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int N = ;
  6.  
  7. long long cnt[N];
  8.  
  9. // 快速幂
  10. long long power(long long a, long long n)
  11. {
  12. long long ans = ;
  13. while (n > ) {
  14. if ( == n % ) ans *= a;
  15. a *= a; n /= ;
  16. }
  17. return ans;
  18. }
  19.  
  20. int main()
  21. {
  22. long long n;
  23. while (cin >> n && != n) {
  24. cnt[] = ;
  25. for (int i = ; i <= n; i++) {
  26. // 递推公式
  27. cnt[i] = * cnt[i - ] + power(, i - ) - cnt[i - ];
  28. }
  29. cout << cnt[n] << endl;
  30. }
  31. return ;
  32. }

B - 危险的组合(Critical Mass,UVa580)

C - 杆子的排序(Pole Arrangement,UVa1638)

设有$n$个杆子,从左边看能看到$l$根,从右边看能$r$跟时的答案是$f(n,l,r)$,插入高度为n的杆子不好讨论,所以考虑插入高度为1的杆子时的有三种情况:

  • 插到最左边,则从左边能看见,从右边看不见,这时有$f(n-1,l-1,r)$种可能
  • 插到最右边,则从右边能看见,从左边看不见,这时有$f(n-1,l,r-1)$种可能
  • 插到中间(有$n-2$个插入的位置),不管从右边还是左边都看不见,这时有$f(n-1,l,r)*(n-2)$

得出递推关系式$f(n,l,r)=f(n-1,l-1,r)+f(n-1,l,r-1)+f(n-1,l,r)*(n-2)$

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int N = ;
  6.  
  7. long long cnt[N][N][N];
  8. long long n, l, r, t;
  9.  
  10. void init()
  11. {
  12. cnt[][][] = ;
  13. for (long long i = ; i <= ; i++) {
  14. for (long long l = ; l <= i; l++) {
  15. for (long long r = ; r <= i; r++) {
  16. cnt[i][l][r] = cnt[i - ][l - ][r] + cnt[i - ][l][r - ] + (i - ) * cnt[i - ][l][r];
  17. }
  18. }
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. init(); cin >> t;
  25. while (t--) {
  26. cin >> n >> l >> r;
  27. cout << cnt[n][l][r] << endl;
  28. }
  29. return ;
  30. }

C - 杆子的排序(Pole Arrangement,UVa1638)

D - 比赛名次(Race,UVa12034)

设答案为$f(n)$,假设第一名有$i$个人,则有$C(n,i)$种可能,接下来的有$f(n-i)$种可能性,所以答案$f(n)=\sum_{i=1}^{i=n} C(n,i)*f(n-i)$,打个表即可

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int N = ;
  6. const int P = ;
  7.  
  8. long long C[N][N];
  9. long long F[N];
  10. long long t, n, icas;
  11.  
  12. void init()
  13. {
  14. for (int i = ; i < N; i++) C[i][] = i, C[i][] = ;
  15. for (int i = ; i < N; i++) {
  16. for (int j = ; j <= i; j++) {
  17. C[i][j] = (C[i - ][j] + C[i - ][j - ]) % P;
  18. }
  19. }
  20. F[] = F[] = ;
  21. for (int n = ; n < N; n++) {
  22. for (int i = n; i >= ; i--) {
  23. F[n] = (F[n] + (F[n - i] * C[n][i]) % P) % P;
  24. }
  25. }
  26. }
  27.  
  28. int main()
  29. {
  30. init(); cin >> t;
  31. while (t--) {
  32. cin >> n;
  33. cout << "Case " << ++icas << ": " << F[n] << endl;
  34. }
  35. return ;
  36. }

D - 比赛名次(Race,UVa12034)

E - 麻球繁衍(Tribbles,UVa11021)

由于每只的麻球的后代独立存活,所以只用求出一个麻球$m$天后全部死亡的概率$f(m)$,最后的答案就是$f(m)^{k}$

第一天出生的麻球会在$m-1$后全部死亡,所以$f(m)=P_{0} + P_{1}*f(m-1)+P_{2}*f(m-1)^{2} + ...+P_{n-1}*f(m-1)^{n-1}$

第二天出生的麻球会在$m-2$后全部死亡,所以$f(m-1)=P_{0} + P_{1}*f(m-2)+P_{2}*f(m-2)^{2} + ...+P_{n-1}*f(m-2)^{n-1}$

到第$i$天全部死亡的概率$f(i)=P_{0} + P_{1}*f(i-1)+P_{2}*f(i-1)^{2} + ...+P_{n-1}*f(i-1)^{n-1}$

  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstring>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const int N = ;
  9.  
  10. double p[N], f[N];
  11. int t, n, k, m, icas;
  12.  
  13. int main()
  14. {
  15. cin >> t;
  16. while (t--) {
  17. cin >> n >> k >> m;
  18. memset(f, , sizeof(f));
  19. for (int i = ; i < n; i++) cin >> p[i];
  20. for (int i = ; i <= m; i++) {
  21. double tp = ;
  22. for (int j = ; j < n; j++) {
  23. f[i] += (p[j] * tp), tp *= f[i - ];
  24. }
  25. }
  26. double res = ;
  27. for (int i = ; i < k; i++) res *= f[m];
  28. cout << "Case #" << ++icas << ": " << fixed << setprecision() << res << endl;
  29. }
  30. return ;
  31. }

E - 麻球繁衍(Tribbles,UVa11021)

F - 玩纸牌(Expect the Expected,UVa11427)

设$p(i,j)$表示玩$i$局赢$j$局的概率,所以当$j>0$时,$p(i,j)=p(i-1,j-1)*\frac{a}{b}+p(i-1,j)*(1-\frac{a}{b})$,当$j=0$时,第$i$局输,所以$p(i,j)=p(i-1,j)*(1-\frac{a}{b})$

设每天晚上垂头丧气去睡觉的概率为$q$,所以$q=\sum_{i=0}^{i*b\leqslant a*n}p(n,i)$

设数学期望为$E$天,第一天晚上有两种情况发生:

  • 第一天晚上垂头丧气去睡觉,概率为$q$,所以能玩纸牌天数的数学期望为1
  • 第一天晚上高高兴兴去睡觉,概率为$1 - q$,因为第一天和第二天独立,所以能玩纸牌天数的数学期望为$E + 1$

根据全期望公式有$E = q * 1 + (1 - q) * (E + 1)$,解得$E = 1 / q$

  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. const int N = ;
  7.  
  8. char ch;
  9. int t, n, a, b, icas;
  10. double p[N][N];
  11.  
  12. double cal()
  13. {
  14. memset(p, , sizeof(p));
  15. p[][] = ;
  16. for (int i = ; i <= n; i++) {
  17. for (int j = ; j <= i && j * b <= a * i; j++) {
  18. if (j > ) p[i][j] = p[i - ][j - ] * a / b + p[i - ][j] * ( - 1.0 * a / b);
  19. else p[i][j] = p[i - ][j] * ( - 1.0 * a / b);
  20. }
  21. }
  22. double q = ;
  23. for (int i = ; i <= n && i * b <= a * n; i++) q += p[n][i];
  24. return int(1.0 / q);
  25. }
  26.  
  27. int main()
  28. {
  29. cin >> t;
  30. while (t--) {
  31. cin >> a >> ch >> b >> n;
  32. cout << "Case #" << ++icas << ": " << cal() << endl;
  33. }
  34. return ;
  35. }

F - 玩纸牌(Expect the Expected,UVa11427)

G - 得到1(Race to 1,UVa11762)

设$f(x)$为当前数为$x$时接下来需要操作的次数,不超过$x$的素数个数为$p(x)$,不超过$x$而且能被$x$整除的素数个数为$g(x)$

每一次选取都要操作一次,所以由全概率公式有$f(x)=1+[1-\frac{g(x)}{p(x)}]*f(x)+\sum _{0=x\%y}\frac{f(\frac{x}{y})}{p}$

化简后得$f(x)=\frac{p(x)+\sum _{0=x\%y}\frac{f(\frac{x}{y})}{p}}{g(x)}$

  1. #include <iostream>
  2. #include <cstring>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. const int N = ;
  8.  
  9. int isprime[N];
  10. int prime[N];
  11. int vis[N];
  12. double f[N];
  13. int tot, t, n, icas;
  14.  
  15. void get_prime(int n)
  16. {
  17. memset(isprime, , sizeof(isprime));
  18. for (int i = ; i <= n; i++) {
  19. if (!isprime[i]) prime[++tot] = i;
  20. for (int j = ; j <= tot; j++) {
  21. if (i * prime[j] > n) break;
  22. isprime[i * prime[j]] = ;
  23. if ( == i % prime[j]) break;
  24. }
  25. }
  26. }
  27.  
  28. double dp(int x)
  29. {
  30. if ( == x) return ;
  31. if (vis[x]) return f[x];
  32. vis[x] = ; int p = , g = ; double ans = ;
  33. for (int i = ; i <= tot && prime[i] <= x; i++) {
  34. p += ;
  35. if ( == x % prime[i]) { g += ; ans += dp(x / prime[i]); }
  36. }
  37. ans = (ans + p) / g;
  38. return f[x] = ans;
  39. }
  40.  
  41. int main()
  42. {
  43. get_prime(N); cin >> t; f[] = ;
  44. while (t--) {
  45. cin >> n;
  46. cout << "Case " << ++icas << ": ";
  47. cout << fixed << setprecision() << dp(n) << endl;
  48. }
  49. return ;
  50. }

G - 得到1(Race to 1,UVa11762)

H - 决斗(Headshot,UVa1636)

设字符串的长度为$n$,子串中00的个数为$a$,0的个数为$b$,分别求直接再抠一枪和随机转一下的条件概率

  • 直接再抠一枪,因为第一个是0,所以在第一个是0的条件下再抠一枪还是0的概率是$\frac{a}{b}$
  • 随机转一下还是0的概率即是字串中0的个数,即$\frac{b}{n}$

两者同时乘$b*n$后比较两者大小即可

  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string s;
  7.  
  8. int main()
  9. {
  10. while (cin >> s) {
  11. int a = , b = , n = (int)s.size();
  12. for (int i = ; i < n; i++) {
  13. if ('' == s[i]) a += ;
  14. if ('' == s[i] && '' == s[(i + ) % n]) b += ;
  15. }
  16. if (b * n > a * a) cout << "SHOOT" << endl;
  17. else if (b * n < a * a) cout << "ROTATE" << endl;
  18. else cout << "EQUAL" << endl;
  19. }
  20. return ;
  21. }

H - 决斗(Headshot,UVa1636)

I - 奶牛和轿车(Cows and Cars,UVa10491)

和三门问题一样

  • 第一次选到牛的概率为$\frac{a}{a+b}$,打开$c$扇门后换门选到车的概率为$\frac{b}{a+b-c-1}$
  • 第一次选到车的概率为$\frac{b}{a+b}$,打开$c$扇门后换门就不能选第一次选的门了,所以这是车的数量为$b-1$,所以选到车的概率为$\frac{b-1}{a+b-c-1}$

所以由全概率公式有赢得车的概率为$\frac{a*b+b*(b-1)}{(a+b)*(a+b-c-1)}$

  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. double a, b, c;
  9. while (cin >> a >> b >> c) {
  10. double res = (b * (a + b - )) / ((a + b) * (a + b - c - ));
  11. cout << fixed << setprecision() << res << endl;
  12. }
  13. return ;
  14. }

I - 奶牛和轿车(Cows and Cars,UVa10491)

J - 条件概率(Probability|Given,UVa11181)

条件概率的公式为$p(E_{i}|E)=\frac{p(E_{i} E)}{p(E)}$

所以要通过深搜算出$n$个人中$r$买物品的概率$p(E)$,算出第$i$个人买物品的同时有$r$个人买物品的概率$p(E_{i} E)$

  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. const int N = ;
  8.  
  9. int n, r, icas;
  10. double p[N], sum[N], tot;
  11.  
  12. void dfs_tot(int cur, int num, double q)
  13. {
  14. if (cur == n) {
  15. if (num == r) tot += q;
  16. return;
  17. }
  18. else {
  19. dfs_tot(cur + , num + , q * p[cur]);
  20. dfs_tot(cur + , num, q * ( - p[cur]));
  21. }
  22. }
  23.  
  24. void dfs_sum(int cur, int num, double q, int idx)
  25. {
  26. if (cur == n) {
  27. if (num == r - ) sum[idx] += q;
  28. return;
  29. }
  30. else {
  31. if (cur != idx) {
  32. dfs_sum(cur + , num + , q * p[cur], idx);
  33. dfs_sum(cur + , num, q * ( - p[cur]), idx);
  34. }
  35. else dfs_sum(cur + , num, q, idx);
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. while (cin >> n >> r) {
  42. memset(sum, , sizeof(sum)), tot = ;
  43. if ( == n && == r) break;
  44. for (int i = ; i < n; i++) cin >> p[i];
  45. dfs_tot(, , );
  46. for (int i = ; i < n; i++) {
  47. dfs_sum(, , , i); sum[i] *= p[i];
  48. }
  49. cout << "Case " << ++icas << ":" << endl;
  50. for (int i = ; i < n; i++) {
  51. cout << fixed << setprecision() << sum[i] / tot << endl;
  52. }
  53. }
  54. return ;
  55. }

J - 条件概率(Probability|Given,UVa11181)

K - 纸牌游戏(Double Patience,UVa1637)

用九元组vector<int> cnt(9,4)来存储状态,用map< vector<int> cnt, double > mp来映射一个状态的成功的概率

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. const int N = ;
  10. const int M = ;
  11.  
  12. map< vector<int>, double > mp;
  13. char ch[N][M][];
  14.  
  15. // 读取
  16. bool read_card()
  17. {
  18. for (int i = ; i < N; i++) {
  19. for (int j = ; j < M; j++) {
  20. if (scanf("%s", ch[i][j]) != ) return false;
  21. }
  22. }
  23. return true;
  24. }
  25.  
  26. // cnt表示牌堆状态,c表示现在卡牌的数量
  27. double dp(vector<int> &cnt, int c)
  28. {
  29. if ( == c) return ;
  30. if ( != mp.count(cnt)) return mp[cnt];
  31. int tot = ; double sum = ;
  32. for (int i = ; i < N; i++) { // 选中的第一个牌堆
  33. for (int j = i + ; j < N; j++) { // 选中的第二个牌堆
  34. if (cnt[i] && cnt[j] && ch[i][cnt[i] - ][] == ch[j][cnt[j] - ][]) {
  35. // 两个牌堆都有牌而且顶部的卡牌满足要求
  36. cnt[i] -= , cnt[j] -= ;
  37. tot += , sum += dp(cnt, c - );
  38. cnt[i] += , cnt[j] += ;
  39. }
  40. }
  41. }
  42. if (!tot) return mp[cnt] = ;
  43. else return mp[cnt] = sum / tot;
  44. }
  45.  
  46. int main()
  47. {
  48. while (read_card()) {
  49. vector<int> cnt(, ); // 初始化状态,9个牌堆,一个牌堆4张牌
  50. mp.clear();
  51. printf("%.6lf\n", dp(cnt, ));
  52. }
  53. return ;
  54. }

K - 纸牌游戏(Double Patience,UVa1637)

L - 过河(Crossing Rivers,UVa12230)

由于船在每个位置概率是相等的,所以过每条河的时间为$\frac{L}{v}$到$\frac{3* L}{v}$均匀分布,因此过河时间为$\frac{2* L}{v}$,再加上$D-sum(L)$

  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. const int N = ;
  7.  
  8. double p[N], l[N], v[N];
  9. double n, d, sum_l, res;
  10. int icas;
  11.  
  12. int main()
  13. {
  14. while (cin >> n >> d) {
  15. if ( == n && == d) break;
  16. sum_l = , res = ;
  17. for (int i = ; i < n; i++) {
  18. cin >> p[i] >> l[i] >> v[i];
  19. sum_l += l[i], res += * l[i] / v[i];
  20. }
  21. res += (d - sum_l);
  22. cout << "Case " << ++icas << ": ";
  23. cout << fixed << setprecision() << res << endl << endl;
  24. }
  25. return ;
  26. }

L - 过河(Crossing Rivers,UVa12230)

M - 糖果(Candy,UVa1639)

假设最后一次打开第一个盒子,此时第二个盒子有$i$颗糖,则在这之前一共打开过$2*n-i$次盒子,其中有$n$次打开第一个盒子,最后一次要打开第一个盒子,所以概率为$C_{2*n-i}^{n}*p^{n+1}*(1-p)^{n-i}$

取对数有$v1(i)=In(C_{2*n-i}^{n})+(n+1)*In(p)+(n-i)*In(1-p)$,化简的$In(C_{2*n-i}^{n})=In\frac{(2*n-i)!}{n!*(n-i)!}=\sum _{k=1}^{2*n-i}In(k)-\sum _{k=1}^{n}In(k)$

所以$v1(i)=\sum _{k=1}^{2*n-i}In(k)-\sum _{k=1}^{n}In(k)+(n+1)*In(p)+(n-i)*In(1-p)$

同理$v2(i)=\sum _{k=1}^{2*n-i}In(k)-\sum _{k=1}^{n}In(k)+(n+1)*In(1-p)+(n-i)*In(p)$

  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. const int N = ;
  8.  
  9. long double logc[ * N];
  10. long double p, res;
  11. int n, icas;
  12.  
  13. void init()
  14. {
  15. for (int i = ; i < * N; i++) logc[i] = logc[i - ] + log(i);
  16. }
  17.  
  18. int main()
  19. {
  20. init();
  21. while (cin >> n >> p) {
  22. res = ;
  23. for (int i = ; i <= n; i++) {
  24. long double c = logc[ * n - i] - logc[n] - logc[n - i];
  25. long double v1 = c + (n + ) * log(p) + (n - i) * log( - p);
  26. long double v2 = c + (n + ) * log( - p) + (n - i) * log(p);
  27. res += (i * (exp(v1) + exp(v2)));
  28. }
  29. cout << "Case " << ++icas << ": ";
  30. cout << fixed << setprecision() << res << endl;
  31. }
  32. return ;
  33. }

M - 糖果(Candy,UVa1639)

N - 优惠券(Coupons,UVa10288)

当已经拿到$k$张后,拿第$k+1$张时,拿到的概率为$Q=\frac{n-k}{n}$

设拿到第$k+1$的期望为$E$,分两种情况:

  • 第一次就拿到第$k+1$张,概率为$Q$,期望是1
  • 第一次没有拿到,因为每次拿都是独立的,所以概率为$1-Q$,期望是$E+1$

由全期望公式得$Q+(1-Q)*(E+1)=E$,解得$E=\frac{1}{Q}=\frac{n}{n-k}$

所以答案为$\sum _{k=0}^{n-1}\frac{n}{n-k}$

  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7.  
  8. ll n, n_up, n_down, pre;
  9. ll num_pre, num_n_up, num_n_down;
  10.  
  11. ll gcd(ll a, ll b)
  12. {
  13. return == b ? a : gcd(b, a % b);
  14. }
  15.  
  16. void cal(ll up, ll down)
  17. {
  18. ll tp_up = n_up * down + n_down * up;
  19. ll tp_down = n_down * down;
  20. pre += (tp_up / tp_down), tp_up %= tp_down;
  21. ll gcd_num = gcd(tp_up, tp_down);
  22. if ( != gcd_num) n_up = tp_up / gcd_num, n_down = tp_down / gcd_num;
  23. else n_up = tp_up, n_down = tp_down;
  24. }
  25.  
  26. int main()
  27. {
  28. while (cin >> n) {
  29. n_up = n_down = n, pre = ;
  30. num_pre = num_n_up = num_n_down = ;
  31. for (ll i = n - ; i >= ; i--) cal(n, i);
  32. ll tp_n_up = n_up, tp_n_down = n_down, tp_pre = pre;
  33. if ( == n_up) cout << pre << endl;
  34. else if ( == pre) cout << << endl;
  35. else {
  36. while (tp_n_up) num_n_up += , tp_n_up /= ;
  37. while (tp_n_down) num_n_down += , tp_n_down /= ;
  38. while (tp_pre) num_pre += , tp_pre /= ;
  39. ll num_ = max(num_n_up, num_n_down);
  40. for (int i = ; i < num_pre + ; i++) cout << " ";
  41. cout << n_up << endl;
  42. cout << pre << " ";
  43. for (int i = ; i < num_; i++) {
  44. if (i == num_ - ) cout << "-" << endl;
  45. else cout << "-";
  46. }
  47. for (int i = ; i < num_pre + ; i++) cout << " ";
  48. cout << n_down << endl;
  49. }
  50. }
  51. return ;
  52. }

N - 优惠券(Coupons,UVa10288)

  ['vektə]  详细X
基本翻译
n. 矢量;带菌者;航线
vt. 用无线电导航
网络释义
vector: 载体
vector graphics: 矢量图形

2019暑期集训第二讲 - 组合数学&概率&数学期望的更多相关文章

  1. best coder #35-01<组合数学 || 概率数学>

    问题描述 一个盒子里有n个黑球和m个白球.现在DZY每次随机从盒子里取走一个球,取了n+m次后,刚好取完.DZY用这种奇怪的方法生成了一个随机的01串S[1⋯(n+m)].如果DZY第i次取出的球是黑 ...

  2. 算法讲堂二:组合数学 & 概率期望DP

    组合数学 1. 排列组合 1. 加法原理 完成一列事的方法有 n 类,其中第 i 类方法包括\(a_i\)种不同的方法,且这些方法互不重合,则完成这件事共有 \(a_1 + a_2 + \cdots ...

  3. $2019$ 暑期刷题记录1:(算法竞赛DP练习)

    $ 2019 $ 暑期刷题记录: $ POJ~1952~~BUY~LOW, BUY~LOWER: $ (复杂度优化) 题目大意:统计可重序列中最长上升子序列的方案数. 题目很直接的说明了所求为 $ L ...

  4. 暑期集训日志(Day6~Day17)

    章·十七:2019-07-28:为谁辛苦为谁甜 ·昨日小结 颓爆了QAQ,昨天又垫底了. 最简单一道题弃疗的我直接被甩倒了总榜垫底…… 我……不想说啥…… 我是渣比. 我不能颓废了. 醒来啊麦克白! ...

  5. 2014年CCNU-ACM暑期集训总结

    2014年CCNU-ACM暑期集训总结 那个本期待已久的暑期集训居然就这种.溜走了.让自己有点措手不及.很多其它的是对自己的疑问.自己是否能在ACM这个领域有所成就.带着这个疑问,先对这个暑假做个总结 ...

  6. 【整理】简单的数学期望和概率DP

    数学期望 P=Σ每一种状态*对应的概率. 因为不可能枚举完所有的状态,有时也不可能枚举完,比如抛硬币,有可能一直是正面,etc.在没有接触数学期望时看到数学期望的题可能会觉得很阔怕(因为我高中就是这么 ...

  7. 2014 SCAU_ACM 暑期集训

    暑期集训,希望能在这段时间获得对得起自己的提升吧 时间:7.11~8.30 集训各专题内容: 1.贪心,递推,基础DP(背包,区间DP,状态压缩DP(去年出了不少于2道铜牌题,看着办)) 2.搜索(B ...

  8. SDU暑期集训排位(5)

    SDU暑期集训排位(5) A. You're in the Army Now 题意 类似选志愿.每个人有 mark,有优先级从高到低的志愿. 做法 定睛一看,鲨鼻题.然后 WA. 为什么会 WA 呢? ...

  9. UVa 11427 Expect the Expected (数学期望 + 概率DP)

    题意:某个人每天晚上都玩游戏,如果第一次就䊨了就高兴的去睡觉了,否则就继续直到赢的局数的比例严格大于 p,并且他每局获胜的概率也是 p,但是你最玩 n 局,但是如果比例一直超不过 p 的话,你将不高兴 ...

随机推荐

  1. pyqt中定时器的使用

    1.定义一个定时器函数 # 定时器 from PyQt5.QtCore import QTimer def timer_start(): timer = QTimer() # fun1是监听的函数,如 ...

  2. office自签名证书

    在 Office安装目录,找到 SELFCERT 文件,双击打开填写名称,生成

  3. AttributeError: This QueryDict instance is immutable

    当写添加注册后端时,运行当运行时,会出现: "AttributeError: This QueryDict instance is immutable": 因为默认的 QueryD ...

  4. easyExcel+poi导出Excel出现乱码

    这种问题肯定是浏览器编码问题,修改官方给的util就好了

  5. word中如何删除一张空白表格

    百度知道:https://baijiahao.baidu.com/s?id=1631677477148377412&wfr=spider&for=pc 当word中出现如下一张空白表格 ...

  6. C:数组基础

    数组 在程序设计中,为了方便处理数据把具有相同类型的若干变量按有序形式组织起来--称为数组. 数组就是在内存中连续的相同类型的变量空间.同一个数组所有的成员都是相同的数据类型,同时所有的成员在内存中的 ...

  7. spring中@Component注解

    1.@controller 控制器(注入服务) 2.@service 业务(注入dao) 3.@repository dao(实现dao访问) 4.@component (把普通pojo实例化到spr ...

  8. 【Struts 动态表单】DynaActionForm

    RegisterAction package k.action; import org.apache.struts.action.ActionForm; import org.apache.strut ...

  9. 洛谷 P5018 对称二叉树(搜索)

    嗯... 题目链接:https://www.luogu.org/problem/P5018 其实这道题直接搜索就可以搜满分: 首先递归把每个点作为根节点的儿子的数量初始化出来,然后看这个节点作为根节点 ...

  10. Centos610 Oracle 监听文件配置参考

    lister.ora配置参考 # listener.ora Network Configuration File: /home/oracle/app/oracle/product//dbhome_1/ ...