📄 pku1923.cpp
字号:
#include <stdio.h>
#define ONLINE
#ifndef ONLINE
#include <time.h>
#endif
int N, M;
int found;
void DFS(int max, int ans, int left)
{
int i;
if (found)
{
return;
}
if (left == 0 && ans == M)
{
found = 1;
return;
}
if (ans > M || ans + left * (left - 1) / 2 < M)
return;
for (i = max; i > 0; i--)
{
DFS(i, ans + i * (left - i), left - i);
}
}
int main()
{
#ifndef ONLINE
freopen("PKU1923.in", "r", stdin);
clock_t start = clock();
#endif
int t = 1;
while (EOF != scanf("%d %d", &N, &M) && (M + N))
{
found = 0;
DFS(N, 0, N);
if (found)
printf("Case %d: %d lines with exactly %d crossings can cut the plane into %d pieces at most.\n", t++, N, M, N + M + 1);
else
printf("Case %d: %d lines cannot make exactly %d crossings.\n", t++, N, M);
}
#ifndef ONLINE
printf("TIME:%dms\n", clock() - start);
#endif
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -