PKU : 1942 - Paths on a Grid
アルゴリズム
(w+h) Choose (h) を計算すればいいだけです.
プログラム
#include <iostream> #include <map> #include <cstring> using namespace std; typedef long long ll; ll cmb(ll n, ll r){ ll res = 1; if(n < 2 * r) r = n - r; for(ll i = 0; i < r; i++) res = (res * (n-i)) / (i+1); return res; } int main(){ ll w,h; while(cin>>w>>h,w||h){ cout<<cmb(w+h,h)<<endl; } }