Source Code
Problem: 1378 User: 20220556****
Memory: 1196K Time: 281MS
Language: G++ Result: Accepted
Source Code
#include <stdio.h>
int count;
int maxcal(int a)
{
return a * (a - 1) / 2;
}
int min(int a, int b)
{
return a > b ? b : a;
}
void dfs(int deep, int limit, int total)
{
if (deep == 0)
{
count++;
return;
}
for (int i = min(total - maxcal(deep),limit);; i--)
{
if (total > ((i+i-deep+1)*(deep) / 2))
{
return;
}
dfs(deep - 1, i-1, total - i);
}
}
int main()
{
int k;
scanf("%d", &k);
while (k--)
{
count = 0;
int n, m;
scanf("%d %d", &n, &m);
dfs(m, 128, n);
printf("%d\n", count);
}
}
无聊,200多毫秒,我要看到血流成河