版本比较
4.27 总结
正文
增加 16 行删除 16 行
9 行未改动101112131415161718192021222324252627282930313233343536373820 行未改动596061626364656667686970717220 行未改动939495969798991001011021033 行未改动10710810911011111211311411511611711811912012112212312412512632 行未改动15916016116216316416516616716816917017115 行未改动9 行未改动的值,保留两位小数。## Solution按题意来做,从顶层开始一直向下递归,没啥好说的。Teacher.J 说这也是送分题,但我没做出来,小数递归写着写着写乱了。## Code```cpp#include <bits/stdc++.h>using namespace std;#define int long longdouble ans[10005];double dfs(double x,int st) {if(st == 0) return 1;//递归结束if(ans[st] != -1) return ans[st];//算过就不再算了ans[st] = st * 1.0 / (st + dfs(st - 1));//计算这一层的值return ans[st];}signed main() {int n;double t,x;cin >> t >> x;for(int i = 1;i <= 10000;i ++) {ans[i] = -1;}while(t --) {//多组数据cin >> n;double anss = dfs(x,n);printf("%.2lf\n",anss);}20 行未改动const int Mod = 1e9 + 7;int n,a,b,c;map<int,int>mp;int dfs(int st) {if(mp.count(st)) return mp[st];//找过的不再找一次if(st <= c) return 1;//Game overint res1 = dfs(st - a) % Mod;int res2 = dfs(st - b) % Mod;return mp[st] = (res1 + res2) % Mod;//我合着写就挂了,玄学?//记忆化}signed main() {cin >> n >> a >> b >> c;cout << dfs(n) % Mod;20 行未改动int dfs(int x,int y) {if(dp[x][y] != -1) return dp[x][y];for(int d = 0;d < 4;d ++) {int px = x + dx[d],py = y + dy[d];if(px < 1 || px > r || py < 1 || py > c) continue; //越界if(high[px][py] < high[x][y]) {//是不是比当前位置小dp[x][y] = max(dp[x][y],dfs(px,py) + 1); //神秘的转移}}return dp[x][y];}3 行未改动for(int j = 1;j <= c;j ++) {cin >> high[i][j];}}for(int i = 1;i <= r;i ++) {//初始化for(int j = 1;j <= c;j ++) {dp[i][j] = -1;}}int ans = -91917891;//恶趣味for(int i = 1;i <= r;i ++) {//找答案for(int j = 1;j <= c;j ++) {ans = max(ans,dfs(i,j));}}cout << ans + 2;//没算起点和终点}```# P5635 【CSGRound1】天下第一32 行未改动cin >> x >> y;int f = 1,i = 1;mp.clear();while(f == 1) {if(mp.count({x,y})) {//判平局cout << "error" << endl;f = 0;}if(i % 2 == 1) { // 奇数回合,代表本回合对x进行改变mp[{x,y}] = 1;x = (x + y) % p;if(x == 0) {cout << 1 << endl;15 行未改动9 行未改动101112131415161718192021222324252627282930313233343536373820 行未改动596061626364656667686970717220 行未改动939495969798991001011021033 行未改动10710810911011111211311411511611711811912012112212312412512632 行未改动15916016116216316416516616716816917017115 行未改动9 行未改动的值,保留两位小数。## Solution按题意来做,从顶层开始一直向下递归,没啥好说的。Teacher.J 说这也是送分题,但我没做出来,小数递归写着写着写乱了。## Code```cpp#include <bits/stdc++.h>using namespace std;#define int long longdouble ans[10005];double dfs(double x,int st) {if(st == 0) return 1;//递归结束if(ans[st] != -1) return ans[st];//算过就不再算了ans[st] = st * 1.0 / (st + dfs(st - 1));//计算这一层的值return ans[st];}signed main() {int n;double t,x;cin >> t >> x;for(int i = 1;i <= 10000;i ++) {ans[i] = -1;}while(t --) {//多组数据cin >> n;double anss = dfs(x,n);printf("%.2lf\n",anss);}20 行未改动const int Mod = 1e9 + 7;int n,a,b,c;map<int,int>mp;int dfs(int st) {if(mp.count(st)) return mp[st];//找过的不再找一次if(st <= c) return 1;//Game overint res1 = dfs(st - a) % Mod;int res2 = dfs(st - b) % Mod;return mp[st] = (res1 + res2) % Mod;//我合着写就挂了,玄学?//记忆化}signed main() {cin >> n >> a >> b >> c;cout << dfs(n) % Mod;20 行未改动int dfs(int x,int y) {if(dp[x][y] != -1) return dp[x][y];for(int d = 0;d < 4;d ++) {int px = x + dx[d],py = y + dy[d];if(px < 1 || px > r || py < 1 || py > c) continue; //越界if(high[px][py] < high[x][y]) {//是不是比当前位置小dp[x][y] = max(dp[x][y],dfs(px,py) + 1); //神秘的转移}}return dp[x][y];}3 行未改动for(int j = 1;j <= c;j ++) {cin >> high[i][j];}}for(int i = 1;i <= r;i ++) {//初始化for(int j = 1;j <= c;j ++) {dp[i][j] = -1;}}int ans = -91917891;//恶趣味for(int i = 1;i <= r;i ++) {//找答案for(int j = 1;j <= c;j ++) {ans = max(ans,dfs(i,j));}}cout << ans + 2;//没算起点和终点}```# P5635 【CSGRound1】天下第一32 行未改动cin >> x >> y;int f = 1,i = 1;mp.clear();while(f == 1) {if(mp.count({x,y})) {//判平局cout << "error" << endl;f = 0;}if(i % 2 == 1) { // 奇数回合,代表本回合对x进行改变mp[{x,y}] = 1;x = (x + y) % p;if(x == 0) {cout << 1 << endl;15 行未改动