码迷,mamicode.com
首页 > 移动开发 > 详细

poj 1664 put apples

时间:2014-10-24 22:04:33      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   strong   

题目链接:http://poj.org/problem?id=1664

思路:

数据较小,考虑深度优先搜索搜索解空间。

 

代码:

#include <iostream>
using namespace std;

int M, N, Count = 0;

void dfs( int deep, int x, int put )
{
    if ( deep == N )
    {
        if ( put == M )
            Count++;
        else
            return;
    }
    else
    {
        for ( int i = x; i <= M; ++i )
        {
            if ( put + i > M )
                break;
            dfs( deep+1, i, put+i );
        }
    }
}

int main()
{
    int t;

    cin >> t;
    while ( t-- )
    {
        Count = 0;

        cin >> M >> N;
        dfs( 0, 0, 0 );

        cout << Count << endl;
    }

    return 0;
}

 

poj 1664 put apples

标签:style   blog   http   color   io   os   ar   for   strong   

原文地址:http://www.cnblogs.com/tallisHe/p/4049384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!