#include<iostream>#include<vector>
using namespace std;constint N =21;int vx[]={0,0,1,-1};int vy[]={1,-1,0,0};int xba[N];int yba[N];int path[N*N];int n, idx;
bool st[N][N];inlinevoiddfs(int x,int y){if(x == n-1&& y == n-1){for(int i =0; i < n-1; i++){if(xba[i]|| yba[i])return;}if(xba[n-1]==1&& yba[n-1]==1){path[idx ++]= n*y+x;for(int j =0; j < idx; j++){cout << path[j]<<' ';}cout << endl;}}for(int i =0; i <4; i++){int nx, ny;nx = x + vx[i], ny = y + vy[i];if(x >=0&& y >=0&& x < n && y < n &&!st[x][y]){st[x][y]= true;xba[x]--;yba[y]--;path[idx ++]= n*y+x;dfs(nx, ny);xba[x]++;yba[y]++;idx--;st[x][y]= false;}}}intmain(){cin >> n;for(int i =0; i < n; i++){cin >> xba[i];}for(int i =0; i < n; i++){cin >> yba[i];}dfs(0,0);}
1、相交链表 本题思路就是定义两指针,指向两链表的同一起跑线,然后共同往前走,边走边判断两链表的节点是否相等, 代码如下:
/*** Definition for singly-linked list.* public class ListNode {* int val;* L…