| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求高手,这样定义状态为什么不对?#include <stdio.h>
#define M 1001
// 状态:定义len[i]为到第i个为止的最大递增子串的长度
// max[i]为这个递增子串中的最大元
// 状态转移方程:则有递归方程 len[i] = max{h[j]}, 0 <= j < i
// h[j] = len[j]+1, if a[i] > max[j]
// h[j] = len[j], else
int main()
{
int a[M], len[M], max[M], n, i, j, k, max_m;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
max[i] = a[i];
len[i] = 1;
}
max_m = -1;
for (i = 1; i < n; i++) {
k = i;
for (j = 0; j < i; j++) {
if (a[i] > max[j]) {
max_m = len[j]+1;
}
else
max_m = len[j];
if (len[i] < max_m) {
len[i] = max_m;
k = j;
}
}
if (a[i] < max[k])
max[i] = max[k];
}
printf("%d\n", len[n-1]);
return 0;
}
验证了好多数据都对,提交就是不对。请问错在哪里了?谢谢
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator