| ||||||||||
| 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<iostream>
#include<stdio.h>
using namespace std;
int a[34][34];
int n;
long long fun(int i,int j)
{
long long s=0;
if(i>(n-1)||j>(n-1)) return 0;
if(i==(n-1)&&j==(n-1))return 1;
if(a[i][j]==0)return 0;
s+=fun(i,(j+a[i][j]));
s+=fun((i+a[i][j]),j);
return s;
}
int main()
{
long long count;
char c;
while(cin>>n&&n!=-1)
{
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
{cin>>c;a[i][j]=c-'0';}
count=fun(0,0);
cout<<count<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator