正文
增加 22 行删除 22 行
17 行未改动181920212223242526272829303132333435363738394041424344454647484950515253542 行未改动5758596061626364656 行未改动727374757677787980818283848586874 行未改动92939495969798991001011021031041051061071081091101111121131144 行未改动1191201211221231241251261275 行未改动13313413513613713813914014114 行未改动1561571581591601611621631643 行未改动17 行未改动## 奇怪的电梯```cpp/*1. 对什么东西选和不选,这次按上还是按下2. 上和下有什么影响假设现在在第x层, 增加k[x]层,或者减少 k[x]3. 什么时候结束,到达b层楼结束4. 答案怎么处理,取最小的按键次数*/#include <bits/stdc++.h>#define int long longusing namespace std;int n, a, b, res = INT_MAX;int k[25], vis[25];void dfs(int x, int cnt) {if (x < 1 or x > n or vis[x] == 1) {// 可行性剪枝return ;}if (x == b) {res = min(res, cnt);return ;}vis[x] = 1; // 标记当前楼层已经走过dfs(x+k[x], cnt+1);dfs(x-k[x], cnt+1);vis[x] = 0;}signed main() {2 行未改动cin >> n >> a >> b;for (int i=1; i<=n; i++) cin >> k[i];dfs(a, 0);if (res == INT_MAX) cout << -1;else cout << res;return 0;}```6 行未改动是一个合法方案。1. 对n个单词选或者不选2. 选单词,它里面的字母出现次数+1不选单词 ,无事发生3. 什么时候结束?n个物品处理完4. 答案要处理什么?所有小写字母都出现过*/#include <bits/stdc++.h>#define int long longusing namespace std;int n, res;string s[20];4 行未改动// 怎么判断答案?int sum = 0;for (int i='a'; i<='z'; i++) {if (t[i] > 0) sum++;}if (sum == 26) res++;return ;}// s[step]string q = s[step]; // 字符串q中的每个字母出现次数增加for (int i=0; i<q.size(); i++) {t[q[i]]++;}dfs(step+1); // 选for (int i=0; i<q.size(); i++) {t[q[i]]--;}dfs(step+1); // 不选}signed main() {ios::sync_with_stdio(0);4 行未改动cin >> s[i];}dfs(1);cout << res;return 0;}```5 行未改动2. 选的影响:木棍总和增加,最大值可能会变化不选的影响:不变3. 什么时候结束:n个物品处理完结束4. 怎么处理答案: 选中的木棍数量大于等于3,并且总长度 > 最大值的两倍*/#include <bits/stdc++.h>using namespace std;14 行未改动dfs(step+1, sum, maxn, cnt);}int main() {cin >> n;for (int i=1; i<=n; i++) cin >> a[i];dfs(1, 0, 0, 0);cout << res;3 行未改动17 行未改动181920212223242526272829303132333435363738394041424344454647484950515253542 行未改动5758596061626364656 行未改动727374757677787980818283848586874 行未改动92939495969798991001011021031041051061071081091101111121131144 行未改动1191201211221231241251261275 行未改动13313413513613713813914014114 行未改动1561571581591601611621631643 行未改动17 行未改动## 奇怪的电梯```cpp/*1. 对什么东西选和不选,这次按上还是按下2. 上和下有什么影响假设现在在第x层, 增加k[x]层,或者减少 k[x]3. 什么时候结束,到达b层楼结束4. 答案怎么处理,取最小的按键次数*/#include <bits/stdc++.h>#define int long longusing namespace std;int n, a, b, res = INT_MAX;int k[25], vis[25];void dfs(int x, int cnt) {if (x < 1 or x > n or vis[x] == 1) {// 可行性剪枝return ;}if (x == b) {res = min(res, cnt);return ;}vis[x] = 1; // 标记当前楼层已经走过dfs(x+k[x], cnt+1);dfs(x-k[x], cnt+1);vis[x] = 0;}signed main() {2 行未改动cin >> n >> a >> b;for (int i=1; i<=n; i++) cin >> k[i];dfs(a, 0);if (res == INT_MAX) cout << -1;else cout << res;return 0;}```6 行未改动是一个合法方案。1. 对n个单词选或者不选2. 选单词,它里面的字母出现次数+1不选单词 ,无事发生3. 什么时候结束?n个物品处理完4. 答案要处理什么?所有小写字母都出现过*/#include <bits/stdc++.h>#define int long longusing namespace std;int n, res;string s[20];4 行未改动// 怎么判断答案?int sum = 0;for (int i='a'; i<='z'; i++) {if (t[i] > 0) sum++;}if (sum == 26) res++;return ;}// s[step]string q = s[step]; // 字符串q中的每个字母出现次数增加for (int i=0; i<q.size(); i++) {t[q[i]]++;}dfs(step+1); // 选for (int i=0; i<q.size(); i++) {t[q[i]]--;}dfs(step+1); // 不选}signed main() {ios::sync_with_stdio(0);4 行未改动cin >> s[i];}dfs(1);cout << res;return 0;}```5 行未改动2. 选的影响:木棍总和增加,最大值可能会变化不选的影响:不变3. 什么时候结束:n个物品处理完结束4. 怎么处理答案: 选中的木棍数量大于等于3,并且总长度 > 最大值的两倍*/#include <bits/stdc++.h>using namespace std;14 行未改动dfs(step+1, sum, maxn, cnt);}int main() {cin >> n;for (int i=1; i<=n; i++) cin >> a[i];dfs(1, 0, 0, 0);cout << res;3 行未改动