int n, m, map[100][100], t, ans = 0, sx, sy, fx, fy; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; bool p[100][100];
voiddfs(int x, int y) { if (x == fx && y == fy) { ans++; return; } p[x][y] = true; for (int i = 0; i < 4; i++) { int x1 = x + dx[i], y1 = y + dy[i]; if (x1 > 0 && x1 <= n && y1 > 0 && y1 <= m && !p[x1][y1] && !map[x1][y1]) dfs(x1, y1); } p[x][y] = false; }
intmain() { int x, y; memset(p, false, sizeof(p)); memset(map, 0, sizeof(map)); cin >> n >> m >> t >> sx >> sy >> fx >> fy; for (int i = 1; i <= t; i++) { cin >> x >> y; map[x][y] = 1; } dfs(sx, sy); cout << ans << endl; return0; }
#include<iostream> usingnamespace std; int n, k, ans = 0; voiddfs(int a, int b, int c) { if (c == 1) { if (b == 0) ans++; return; } for (int i = a; i <= b / (c - 1); i++) dfs(i, b - i, c - 1); } intmain() { cin >> n >> k; for (int i = 1; i <= n / k; i++) dfs(i, n - i, k); cout << ans << endl; return0; }
if __name__ == '__main__': n, L = map(int, input().split()) a = list(map(int, input().split())) vis = defaultdict(int) d = [] # 计算可移动的距离 for i inrange(n): for j inrange(n): nxt = (a[i] + a[j]) % L ifnot vis[nxt] and nxt: d.append(nxt) vis[nxt] = 1 # BFS vis = defaultdict(int) que, head, tail, end = [1], 0, 0, 0 while head <= tail: u = que[head] head += 1 if u == L: end = 1 print(vis[u]) break for k in d: nxt = (u + k - 1) % L + 1 if vis[nxt] or nxt == 1: continue tail += 1 que.append(nxt) vis[nxt] = vis[u] + 1 if end == 0: print(-1)
intmain() { cin >> n >> m; ll x = 1, y = 1; for (int i = 1; i <= (n << 1) - 1; i++) { printf("%lld %lld\n", x, y); mp[(x - 1) * n + y] = 1; if (x == y) y++; else x++; } printf("%lld %d\n", n, 1); ll p = (n << 1) + 1; mp[n * (n - 1) + 1] = 1; for (int i = 1; p <= m; i++) { if (mp[i]) continue; y = i % n; if (y == 0) y = n; x = (i - y) / n + 1; printf("%lld %lld\n", x, y); p++; } return0; }