Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FindSequenceBySum
- {
- static int n = 5;
- static int m = 2;
- static int mm = 0;
- static char[] a = new char[n + 1];
- static int num = 0;
- public static void rec(int idx)
- {
- if (idx == n)
- {
- num++;
- for (int i = 0; i < idx; i++)
- {
- System.out.print(a[i]);
- }
- System.out.println();
- return;
- }
- if (idx == 0 || (a[idx - 1] != '*' && mm != m))
- {
- a[idx] = '*';
- mm++;
- rec(idx + 1);
- mm--;
- }
- a[idx] = '.';
- rec(idx + 1);
- }
- public static void main(String[] args)
- {
- rec(0);
- }
- }
Add Comment
Please, Sign In to add comment