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 hehexiaobai at 2010-08-21 10:27:08 on Problem 1664
#include<iostream>
using namespace std;
int n,m;
int a[11];
void dfs(int cur, int &k)
{ 
     if(cur>n)return ;
     k++;
     int ll=a[cur];
     for(int m=a[cur-1]; m<=ll/2; m++)
     {
             a[cur]=m; a[cur+1]=ll-m;      
             dfs(cur+1,k);
     }
     a[cur]=0;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
              cin>>m>>n;
              int k=0;
              memset(a,0,sizeof a);
              a[0]=1;
              a[1]=m;
              dfs(1,k);
              
              cout<<k<<endl;   
    }
    system("pause");
    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