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 lily at 2005-09-02 22:09:31 on Problem 1664
In Reply To:Re:求助 Posted by:lily at 2005-09-02 22:04:39
程序如下:

#include<iostream>
using namespace std;

int B(int,int);

int main()
{
   int t,m,n;
   cin>>t;
   for(int i=0;i<t;++i)
   {
      cin>>m>>n;
      int sum=0;
      for(int j=1;j<=n;++j)
         sum+=B(m,j);
      cout<<sum<<'\n';
   }
}

int B(int n,int k)
{
   if(k==1||n==k) return 1;
   else
   {
      if(k>n) return 0;
      else
      {
         int result=0;
         for(int l=k;l>0;--l)
            result+=B(n-k,l);
         return result;
      }
   }
}

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