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\n", DFS(m, 1, m));
}
return 0;
}
标签:cnt,1664,return,int,DFS,POJ,ans,include 来源: https://www.cnblogs.com/Idi0t-N3/p/14678998.html