# 实习生笔试

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{

int n;
cin >> n;
vector<int>a(n);
for (int i = 0; i<n; i++)
cin >> a[i];
vector<int>left(n, -1);//left[i]记录a[i]左侧大于a[i]的最大数
vector<int>right(n, -1);//right[i]记录a[i]右侧小于a[i]的最大数
for (int i = 1; i<n; i++)
{
for (int j = 0; j<i; j++)
{
if (a[i]<a[j])
{
left[i] = max(left[i], a[j]);
}
}
}
for (int i = 0; i<n - 1; i++)
{
for (int j = i + 1; j<n; j++)
{
if (a[i]>a[j])
{
right[i] = max(right[i], a[j]);
}
}
}
int res = 0;
for (int i = 1; i<n - 1; i++)
{
if (left[i] != -1 && right[i] != -1)
if (left[i] % right[i] == 0)
{
res++;
}
}
cout << res << endl;

system("pause");
return 0;

}



int main()
{

int n;
cin >> n;
vector<int>a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int>left(n, -1);//left[i]记录a[i]左侧大于a[i]的最大数
vector<int>right(n, -1);//right[i]记录a[i]右侧小于a[i]的最大数

//初始化
if (a[1] < a[0])left[1] = a[0];
if (a[n - 1] < a[n - 2])right[n - 2] = a[n - 1];

for (int i = 2; i < n; i++)
{
if (a[i] < a[i - 1])
{
left[i] = max(left[i - 1], a[i - 1]);
}

}
for (int i = n-2; i >=0; i--)
{

if (a[i] > a[i+1])
{
right[i] = max(right[i+1], a[i + 1]);
}
}
int res = 0;
for (int i = 1; i < n - 1; i++)
{
if (left[i] != -1 && right[i] != -1)
if (left[i] % right[i] == 0)
{
res++;
}
}
cout << res << endl;

system("pause");
return 0;

}


3 4
9 9 1 1
9 1 1 9
1 1 9 9

4

#include<iostream>
#include<vector>
using namespace std;
const int INFINITE = 65536;
void DFS(const vector<vector<int>>&array, vector<vector<int>>&dp, int i, int j, int current_sum, int &res)
{
//递归结束的条件
if (i < 0 || j < 0 || j >= array[0].size())
{
return;
}
//递归结束的条件
if (i<array.size() && array[i][j] + current_sum > dp[i][j])//如果此时同一个值已经被遍历过并且取值更小，则没必要再对它遍历
{
return;
}
//递归结束的条件
if (i == array.size())
{
res = min(res, current_sum);
return;
}

//表示当前格子是可以进入的
//更新dp
dp[i][j] = current_sum + array[i][j];

//开启新的子递归
DFS(array, dp, i + 1, j, current_sum + array[i][j], res);
DFS(array, dp, i - 1, j, current_sum + array[i][j], res);
DFS(array, dp, i, j + 1, current_sum + array[i][j], res);
DFS(array, dp, i, j - 1, current_sum + array[i][j], res);

}
int main()
{
int res = INFINITE;
int n, m;
cin >> n >> m;
vector<vector<int>>dp(n, vector<int>(m, INFINITE));//dp[i][j]表示从某个起点出发走到(i,j)消耗的体力最小值
vector<vector<int>>array(n, vector<int>(m, 0));

for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
cin >> array[i][j];
}
for (int j = 0; j < m; j++)//m个起点
{
DFS(array, dp, 0, j, 0, res);
}

cout << res << endl;
system("pause");
return 0;
}

04-22
05-01 486

05-29 2544
03-23 138
05-06
04-17 1539
08-04 5770
04-18 1011