var booth: array[0..400] of integer; t: array[0..400, 0..400] of integer; dp: array[0..400] of integer; n, i, j, flag, ans: integer; begin readln(n); for i := 0 to n - 1 do readln(booth[i]); for i := 0 to n - 1 do for j := 0 to n - 1 do readln(t[i, j]); for i := 0 to n - 1 do if t[0, i] <= booth[i] then dp[i] := 1; flag := 1; while flag <> 0 do begin flag := 0; for i := 0 to n - 1 do for j := 0 to n - 1 do if (t[i, j] <= (booth[j] - booth[i])) and (dp[j] <= dp[i]) and (i <> j) then begin dp[j] := dp[i] + 1; flag := 1; end; end; ans := 0; for i := 0 to n - 1 do if ans < dp[i] then ans := dp[i]; writeln(ans); end.转换为c语言代码
时间: 2024-01-20 17:02:17 浏览: 98
```c
#include <stdio.h>
int booth[401], t[401][401], dp[401];
int main() {
int n, i, j, flag, ans;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &booth[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &t[i][j]);
}
}
for (i = 0; i < n; i++) {
if (t[0][i] <= booth[i]) {
dp[i] = 1;
}
}
flag = 1;
while (flag != 0) {
flag = 0;
for (i = 0; i < n; i++) {
for (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;
}
}
}
}
ans = 0;
for (i = 0; i < n; i++) {
if (ans < dp[i]) {
ans = dp[i];
}
}
printf("%d\n", ans);
return 0;
}
```
阅读全文