Bestcoder Round #35 (dzy Loves balls-violence DP)

Source: Internet
Author: User

Dzy Loves Ballsaccepts:371submissions:988Time limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others) Problem Description

There is n Black Balls and m White balls in the big box.

Now, Dzy starts-randomly pick out of the balls one by one. It forms a sequence S . If at the i -th operation, Dzy takes out of the black ball, S i =1 , otherwise S i =0 .

Dzy wants to know the expected times that ' "occurs in S .

Input

The input consists several test cases. ( T esTC ase≤ Max )

The first line contains the integers, n , m(1≤N,m≤ A)

Output

For each case, the output of the corresponding result, the format is P/q ( p and q is coprime)

Sample Input
1 12 3
Sample Output
1/26/5hintcase 1:s= ' or s= ', so the expected times = = = 1/2case 2:s= ' 00011 ' or s= ' 00101 ' or s= ' 00110 ' or s= ' 010 "or s= ' 01010 ' or s= ' 01100 ' or s= ' 10001 ' or s= ' 10010 ' or s= ' 10100 ' or s= ' 11000 ', so the expected times = (1+2+1+2+2+1+1+1 +1+0)/10 = 12/10 = 6/5

This time, I started DP-screwing.

Actually, there's a simpler way of knocking the formula, but I'm just going to hand in the table program.

Next_permunation This kind of violence is also possible??


#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include < functional> #include <iostream> #include <cmath> #include <cctype> #include <ctime>using namespace std; #define for (I,n) for (int. i=1;i<=n;i++) #define FORK (I,k,n) for (int. i=k;i<=n;i++) #define REP (I,n) for (int i=0;i<n;i++) #define ForD (I,n) for (int. i=n;i;i--) #define REPD (I,n) for (int. i=n;i>=0;i--) #define FORP (x) for ( int p=pre[x];p; p=next[p]) #define FORPITER (x) for (int &p=iter[x];p; p=next[p]) #define LSON (x<<1) #define Rson ((x<<1) +1) #define MEM (a) memset (A,0,sizeof (a)), #define MEMI (a) memset (A,127,sizeof (a)), #define MEMI (a) memset ( A,128,sizeof (a)); #define INF (2139062143) #define F (100000007) #define MAXN (+) typedef long Long Ll;ll Mul (ll a,ll b) {RE Turn (a*b)%F;} ll Add (ll A,ll b) {return (a+b)%F;} ll Sub (ll A,ll b) {return (a-b+ (a)/f*f+f)%F; void Upd (ll &a,ll b) {a= (a%f+b%f)%F;} ll GCD (ll A,ll b) {if (b==0) return A;return gcd (b,a%b);} ClThe Fenshu{public:ll A, B,//denominator a molecule B. Fenshu (ll _b,ll _a): A (_a), B (_b) {}fenshu (): A (1), B (0) {}void relax () {int t=gcd (a, b); =t,b/=t;} Friend Fenshu operator* (Fenshu A,fenshu b) {Fenshu C=fenshu (A.B*B.B,A.A*B.A); C.relax (); return c;} Friend Fenshu operator+ (Fenshu A,fenshu b) {Fenshu C=fenshu (A.A*B.B+A.B*B.A,A.A*B.A); C.relax (); return c;} void pri () {cout<<b<< '/' <<a;}} F[maxn][maxn][2];int n,m;void turn_out (int n,int m) {Fenshu T=f[n][m][0]*fenshu (m,n) +f[n][m][1]*fenshu (n-m,n); T.pri ( );} int main () {//freopen ("a.in", "R", stdin); n=24,m=12; Fork (i,2,n) Rep (j,i+1) {int K=0;f[i][j][k]=f[i-1][j-1][0]*fenshu (j-1,i-1) +f[i-1][j-1][1]*fenshu (i-j,i-1); K=1;f[i] [j] [K]= (Fenshu () +f[i-1][j][0]) *fenshu (j,i-1) +f[i-1][j][1]*fenshu (i-1-j,i-1);} /*for (i,24) {Rep (J,min (i+1,13)) {turn_out (i,j);cout<< ';} Cout<<endl;} */while (scanf ("%d%d", &n,&m) ==2) {N+=m;fenshu T=f[n][m][0]*fenshu (m,n) +f[n][m][1]*fenshu (n-m,n); T.pri (); Cout<<endl;} return 0;}







Bestcoder Round #35 (dzy Loves balls-violence DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.