一道比较水的题,数据范围很小,打表能过,不过其中的递归思想很不错,很有dp的感觉
int dfs(int m, int n)
{
if ( m == 0 || n == 1 )
return 1;
if ( m < n )
return dfs(m, m);
return dfs(m, n-1)+dfs(m-n, n);
}
这不就是dp了么?边界条件+处理当前状况
#include <stdio.h>
int dfs(int m, int n)
{
if ( m == 0 || n == 1 )
return 1;
if ( m < n )
return dfs(m, m);
return dfs(m, n-1)+dfs(m-n, n);
}
int main()
{
int ncase, m, n;
scanf("%d", &ncase);
while ( ncase-- )
{
scanf("%d%d", &m, &n);
printf("%d\n", dfs(m, n));
}
return 0;
}