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

递归或者DFS都可以,就贴一个DFS吧

Posted by husanfeng at 2012-11-24 10:09:41 on Problem 1664
#include <iostream>
#include <string>

using namespace std;

int t,n,m,s;

int num[11];

void dfs(int x,int y)
{ 
    if(x==m)
    {
        if(y>=num[m-1])
            s++;
    }     
    else 
    {    
        for(int i=num[x-1];i<=y&&(y/(m-x)>=i);i++)
        {
            num[x]=i;
            dfs(x+1,y-i);
        }
    }
}
        
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        memset(num,0,sizeof(num));      
        scanf("%d%d",&n,&m);
        s=0;
        dfs(1,n);
        printf("%d\n",s);
    }
    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