497 - Strategic Defense Initiative
Moderator: Board moderators
I always got a runtime error in 497.
The problem is a multiple input.
Although I read the help very carefully, I
still can't understand what I should do for
reading the input.
I got a confused for a long time.
I don't know what result in this reply.
Is it cause by reading??
or others??
Thx!!
<font size=-1>[ This Message was edited by: hankkuo on 2001-11-09 09:51 ]</font>
The problem is a multiple input.
Although I read the help very carefully, I
still can't understand what I should do for
reading the input.
I got a confused for a long time.
I don't know what result in this reply.
Is it cause by reading??
or others??
Thx!!
<font size=-1>[ This Message was edited by: hankkuo on 2001-11-09 09:51 ]</font>
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore
Hi
I have no idea why i have WA.
Could anyone help me???Program p497;
VAR
stos,tab,wynik,pop:array[1..8000] of integer;
wys,max,maxx,y,ilosc,x:longint;
begin
x:=0;
repeat
x:=x+1;
readln(tab[x]);
until eof;
ilosc:=x;
for x:=1 to ilosc do wynik[x]:=1;
for x:=1 to ilosc do pop[x]:=-1;
for x:=2 to ilosc do
begin
for y:=1 to x-1 do
begin
if tab[x]>=tab[y] then
begin
if wynik[y]+1>wynik[x] then
begin
wynik[x]:=wynik[y]+1;
pop[x]:=y;
end;
end;
end;
end;
max:=0;
maxx:=0;
for x:=1 to ilosc do
begin
if wynik[x]>max then
begin
max:=wynik[x];
maxx:=x;
end;
end;
Writeln('Max hits: ',max);
wys:=0;
repeat
wys:=wys+1;
stos[wys]:=tab[maxx];
maxx:=pop[maxx];
until maxx=-1;
for x:=wys downto 1 do Writeln(stos[x]);
end.
I have no idea????
Please help!!!
I have no idea why i have WA.
Could anyone help me???Program p497;
VAR
stos,tab,wynik,pop:array[1..8000] of integer;
wys,max,maxx,y,ilosc,x:longint;
begin
x:=0;
repeat
x:=x+1;
readln(tab[x]);
until eof;
ilosc:=x;
for x:=1 to ilosc do wynik[x]:=1;
for x:=1 to ilosc do pop[x]:=-1;
for x:=2 to ilosc do
begin
for y:=1 to x-1 do
begin
if tab[x]>=tab[y] then
begin
if wynik[y]+1>wynik[x] then
begin
wynik[x]:=wynik[y]+1;
pop[x]:=y;
end;
end;
end;
end;
max:=0;
maxx:=0;
for x:=1 to ilosc do
begin
if wynik[x]>max then
begin
max:=wynik[x];
maxx:=x;
end;
end;
Writeln('Max hits: ',max);
wys:=0;
repeat
wys:=wys+1;
stos[wys]:=tab[maxx];
maxx:=pop[maxx];
until maxx=-1;
for x:=wys downto 1 do Writeln(stos[x]);
end.
I have no idea????
Please help!!!
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore
I think my DP is correct. Can someone tell me why this code is WA? Thanks:o)
Code: Select all
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
void main()
{
int i,j,k,N,Z,z,BL,BP;
char B[100];
vector<int> D,L,P,R;
scanf("%dnn",&Z);
for(z=0;z<Z;z++)
{
if(z>0)
printf("n");
D.clear();
while(gets(B)!=NULL)
{
if(sscanf(B,"%d",&N)!=1)
{
break;
}
else
{
D.push_back(N);
}
}
L=vector<int>(D.size(),-1);
P=L;
L[0]=1;
P[0]=-1;
for(i=1;i<D.size();i++)
{
BL=1;
BP=-1;
for(j=0;j<i;j++)
{
if(D[j]<D[i])
{
BL=L[j]+1;
BP=j;
}
}
L[i]=BL;
P[i]=BP;
}
j=max_element(L.begin(),L.end())-L.begin();
printf("Max hits: %dn",L[j]);
R.clear();
k=L[j];
while(k>0)
{
R.push_back(D[j]);
k--;
j=P[j];
}
reverse(R.begin(),R.end());
for(i=0;i<R.size();i++)
{
printf("%dn",R[i]);
}
}
}
so many source code posted
Did you read the problem carefully? Dont just post the code and ask why, why, why and why...

-novice.. wrote:In these days, the board is full of source code....
Why do the people just hope others to debug for them?
