zoukankan      html  css  js  c++  java
  • POJ 1664

    这题真实水的无与伦比的快乐,当然中间debug稍微浪费了点时间。很简单的DFS

    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <string>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <stack>
    #include <map>
    #include <set>
    using namespace std;
    
    int n;
    int DFS(int m, int cnt, int mx)
    {
    	if (n== cnt){
    		if (m> mx){
    			return 0;
    		}
    		return 1;
    	}
    	int ans= 0;
    	for (int i= min(mx, m), j= m-i; i>= 0; --i, ++j){
    		ans+= DFS(j, cnt+1, i);
    	}
    
    	return ans;
    }
    
    int main(int argc, char const *argv[])
    {
    	int kase;
    	scanf("%d", &kase);
    
    	while (kase--){
    		int m;
    		scanf("%d %d", &m, &n);
    		printf("%d
    ", DFS(m, 1, m));
    	}
    
    	return 0;
    }
    
  • 相关阅读:
    mysql面试知识点
    计算机网络
    BFS
    拓扑排序
    双指针
    回溯算法
    hash表 算法模板和相关题目
    桶排序及其应用
    滑动窗口
    贪心算法
  • 原文地址:https://www.cnblogs.com/Idi0t-N3/p/14678998.html
Copyright © 2011-2022 走看看