计蒜客 T1866
集训队题目链接
#include自然数的拆分using namespace std; int biao[25],n,m; void dfs(int a,int k) { if(k==m) { for(int i=1;i<=n;++i) { if(biao[i]) { printf("%3d",i); } } putchar('n'); } else { for(int i=a;i<=n;++i) { if(!biao[i]) { biao[i]=1; dfs(i,k+1); biao[i]=0; } } } } int main() { cin>>n>>m; dfs(1,0); return 0; }
计蒜客 T1248
集训队题目链接
#include马跳日using namespace std; int biao[25],n,m; vector v; void dfs(int a,int k) { if(k==n) { printf("%d=",n); for(int i=0;i >n; dfs(1,0); return 0; }
计蒜客 T1217
集训队题目链接
#include中单法师using namespace std; const int N = 20; int n, m, x, y, cnt; int tx[8] = {-2, -1, 1, 2, 2, 1, -2, -1}; int ty[8] = {-1, -2, -2, -1, 1, 2, 1, 2}; bool st[N][N]; void dfs(int x, int y, int t) { if (t == m * n) { cnt++; return; } st[x][y] = true; for (int i = 0; i < 8; i++) { int dx = x + tx[i], dy = y + ty[i]; if (dx < 0 || dx >= n || dy < 0 || dy >= m || st[dx][dy]) continue; dfs(dx, dy, t + 1); } st[x][y] = false; } int main() { int T; scanf("%d", &T); while (T--) { cnt = 0; scanf("%d%d%d%d", &n, &m, &x, &y); dfs(x, y, 1); printf("%dn", cnt); } return 0; }
计蒜客 T1684
集训队题目链接
#include买书using namespace std; const int N = 20; int n; int a[N][2], MIN = 1e9; void dfs(int k, int x, int y) { if (x && y && abs(x - y) < MIN) MIN = abs(x - y); if (k >= n) return ; for (int i = 0; i < 2; ++i) { if (i) dfs(k + 1, x * a[k][0], y + a[k][1]); else dfs(k + 1, x, y); } } int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i][0] >> a[i][1]; dfs(0, 1, 0); cout << MIN << "n"; return 0; }
计蒜客 T1771
集训队题目链接
#include农场扩建using namespace std; int k, MIN = 1e9, st[20] = {-1}; string s; void dfs(int i) { if (i == k) { int sum = 0, idx = 1; int x = 0; for (int j = 0; j < s.length(); ++j) { if (j == st[idx]) { ++idx; sum += x; x = 0; } x = x * 10 + s[j] - '0'; } sum += x; if (sum < MIN) MIN = sum; return ; } for (int j = st[i - 1] + 1; j < s.length(); ++j) { st[i] = j; dfs(i+ 1); } } int main() { cin >> s >> k; dfs(1); cout << MIN << "n"; return 0; }
计蒜客 T1211
集训队题目链接
#includeusing namespace std; const int N = 55; char s[N][N]; int w, h, st[N][N], cnt; int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1}; void dfs(int x, int y) { ++cnt; for (int i = 0; i < 4; ++i) { int xx = x + dx[i]; int yy = y + dy[i]; if (xx >= 0 && xx < w && yy >= 0 && yy < h && !st[xx][yy] && s[xx][yy] == '.') { st[xx][yy] = 1; dfs(xx, yy); } } } int main() { int x, y; cin >> h >> w; for (int i = 0; i < w; ++i) { for (int j = 0; j < h; ++j) { scanf(" %c", &s[i][j]); if (s[i][j] == '@') { x = i; y = j; } } } dfs(x, y); cout << cnt << "n"; return 0; }



