-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardpath(Count_,_Print).cpp
More file actions
53 lines (46 loc) · 968 Bytes
/
Boardpath(Count_,_Print).cpp
File metadata and controls
53 lines (46 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// @author: Abhimanyu Maurya
#include <iostream>
using namespace std;
//fast i/o
bool ib = ios_base::sync_with_stdio(0);
bool it = cin.tie(0);
bool ot = cout.tie(0);
// define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
FILE *fr = freopen("input.txt", "r", stdin);
FILE *fw = freopen("output.txt", "w", stdout);
#endif
int count = 0;
bool boardprint(int num, int dice, char *path, char *ptr)
{
if (num == 0 or dice == 0)
{
count++;
*ptr = '\0';
cout << path << " ";
return true;
}
int less = min(dice, num);
bool res[less + 1];
for (int i = 1; i <= less; i++)
{
*ptr = i + '0';
res[i] = boardprint(num - i, dice, path, ptr + 1);
}
int i = 1;
while (!res[i])
i++;
if (i <= less)
return true;
return false;
}
int main()
{
int n, d;
cin >> n >> d;
char path[100];
boardprint(n, d, path, path);
cout << '\n'
<< count;
return 0;
}