#include<stdio.h> int booth[401],t[401][401],dp[401]; int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&booth[i]); for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d",&t[i][j]); for(int i=0;i<n;i++) if(t[0][i]<=booth[i]) dp[i]=1; int flag=1; while(flag) { flag=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(t[i][j]<=(booth[j]-booth[i])&&dp[j]<=dp[i]&&i!=j) { dp[j]=dp[i]+1; flag=1; } } } } int ans=0; for(int i=0;i<n;i++) if(ans<dp[i]) ans=dp[i]; printf("%d",ans); return 0; }转换为c++代码
时间: 2023-06-21 16:15:15 浏览: 66
以下是将给定的 C 代码转换为 C++ 代码后的结果:
```cpp
#include <iostream>
using namespace std;
int booth[401], t[401][401], dp[401];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> booth[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> t[i][j];
for (int i = 0; i < n; i++)
if (t[0][i] <= booth[i])
dp[i] = 1;
int flag = 1;
while (flag) {
flag = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (t[i][j] <= (booth[j] - booth[i]) && dp[j] <= dp[i] && i != j) {
dp[j] = dp[i] + 1;
flag = 1;
}
}
}
}
int ans = 0;
for (int i = 0; i < n; i++)
if (ans < dp[i])
ans = dp[i];
cout << ans << endl;
return 0;
}
```
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)