没试过给二维数组初始化,不确定怎么搞,比赛时还专门实验了下,作为一个卡壳点记录到笔记本
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
//二维数组打表
int f[7][7] = {0,1,1,2,3,3,4, 1,0,2,1,2,2,3, 1,2,0,1,2,2,3, 2,1,1,0,1,1,2, 3,2,2,1,0,2,1, 3,2,2,1,2,0,1, 4,3,3,2,1,1,0};
int main(){
int t;
cin >> t;
while(t--){
int res = 0;
int s1,s2,e1,e2;
cin >> s1 >> s2 >> e1 >> e2;
s1--,s2--,e1--,e2--;
int ans=0;
ans = f[s1][e1] + f[s2][e2];
res = f[s1][e2] + f[s2][e1];
cout << min(ans,res) << endl;
}
return 0;
}
该代码示例展示了如何初始化二维数组,并在比赛中用于动态规划问题。程序读取输入,计算两个子矩阵的元素和,并找到最小值。
485

被折叠的 条评论
为什么被折叠?



