Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

递归的

Posted by jackch at 2006-10-06 10:30:56 on Problem 2704
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator