Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
高中的排列组合,插空法。。。还记得否???没想到在这里能用上。。。#include <stdio.h> #include <memory.h> __int64 v[50][50]; __int64 c(int m,int n) { if(n==0||m==n)return 1; else if(n==1)return m; else { if(v[m][n]==-1) v[m][n]=c(m-1,n)+c(m-1,n-1); return v[m][n]; } } int main() { int cases ,n,a,b,i,w=0; __int64 sum=0; scanf("%d",&cases); while (cases--) { w++; memset(v,-1,sizeof(v)); sum=0; scanf("%d",&n); a=(int)((n+1)/2); for(i=0;i<=a;i++) { b=n-i+1; sum=sum+c(b,i); } printf("Scenario #%d:\n",w); printf("%I64d\n",sum); if(cases>0)printf("\n"); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator