Friday, November 2, 2012

Pascal Triangle


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
#define siz 1005
typedef long long ll;
ll a[siz][siz];

void pascal(){
    ll i,j;
    a[0][0]=1;
    a[1][0]=a[1][1]=1;
    for(i=2;i<=1000;i++){
        for(j=1;j<=i;j++){
            if(j==1||j==i) a[i][j]=1;
            else a[i][j]=a[i-1][j-1]+a[i-1][j];
        }
    }
}

int main()
{
    pascal();
    ll n,r;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    while(cin>>n>>r){
        if(n==0&&r==0) break;
        cout<<n<<" things taken "<<r<<" at a time is "<<a[n+1][r+1]<<" exactly."<<endl;
    }
    return 0;
}


No comments:

Post a Comment