Accounting | Trading | Tools | Accounts | Login
Kurniady Systems - Tools
 
Tuesday, 07 September 2010 - 17:06:56
Home | About

Viewing Text Document

Title:

INC 2008 Final E

Owner: Andrian Kurniady

Last updated on: Tuesday, 15 July 2008

Description:

My solution for INC 2008 final problem E.

Content:

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;

double dpmat[100][100];

int main(){
    int n,s;
    while (scanf("%d%d", &n,&s)!=EOF){
        memset(dpmat,0,sizeof(dpmat));
        dpmat[0][s]=1;
        
        for (int i=0;i<n;i++){
            dpmat[i+1][0]+=dpmat[i][0]*2.0/3.0;
            for (int j=1;j<=s;j++){
                dpmat[i+1][j]+=dpmat[i][j]*2.0/3.0;
                dpmat[i+1][j-1]+=dpmat[i][j]/3.0;
            }
        }
        
        double res = 0;
        double r0 = dpmat[n][0];
        for (int i=1;i<=s;i++)
            res+=dpmat[n][i];
              
        printf("%.5lf\n", res/(res+r0)*100.0);
    }
    
    return 0;
}

Please note that the document shown may be copyrighted. Please contact the owner of this document for the details.
Valid XHTML and CSS. Powered by Ruby on Rails.
 
Copyright © 2008 by Andrian Kurniady. All rights reserved.