10854 - Number of Paths
Moderator: Board moderators
-
- New poster
- Posts: 9
- Joined: Sun Mar 13, 2005 11:41 am
10854 - Number of Paths
I'm getting this program WA WA and WA.
I want just some tests.I want to know is answer always even or 1 can answer be 0.
Please give some tests.It seems ease but WA.
I want just some tests.I want to know is answer always even or 1 can answer be 0.
Please give some tests.It seems ease but WA.
Perhaps this answers your questions?
input:
output:
input:
Code: Select all
4
ENDPROGRAM
S
ENDPROGRAM
IF
ELSE
END_IF
ENDPROGRAM
IF
ELSE
IF
ELSE
END_IF
END_IF
ENDPROGRAM
Code: Select all
1
1
2
3
The output must be positive integer. For any possible output, you can easily generate the corresponding input like the pattern below:
The ouput of this case is 9.
Code: Select all
1
IF
IF
IF
IF
IF
IF
IF
IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ENDPROGRAM
-
- New poster
- Posts: 9
- Joined: Sun Mar 13, 2005 11:41 am
What is answer for this inout
Code: Select all
1
IF
IF
IF
IF
IF
IF
IF
IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
IF
IF
IF
IF
IF
IF
IF
IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ELSE
END_IF
ENDPROGRAM
The correct answer is 81.
Lets take this simple Programm to show you the idea:
Here all IF-Conditions can be true, short: TTT
Or the first two are true and the third false, short: TTF
And so on to FFF
So at all there are 2*2*2=8 possibilities.
So the answer to the sample Input is 9*9=81 and not 9+9=18.
Lets take this simple Programm to show you the idea:
Code: Select all
IF
ELSE
END_IF
IF
ELSE
END_IF
IF
ELSE
END_IF
ENDPROGRAM
Or the first two are true and the third false, short: TTF
And so on to FFF
So at all there are 2*2*2=8 possibilities.
So the answer to the sample Input is 9*9=81 and not 9+9=18.
I got WAs again. I was tired out by this problem.
Who could send your souce code to me!
My e-mail address is: zhangfan555@tom.com
Thx.
Who could send your souce code to me!
My e-mail address is: zhangfan555@tom.com
Thx.
Still WA,Who can tell me why?Thank u!!


Code: Select all
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
long long count1=0;
char com[805000];
long long find(long long from,long long end){
//cout<<from<<' '<<end<<endl;
//if(from==end) return 1;
//if(from+1==end) return 1;
if(from==end+1) return 1;
long long i=0,ans,p=0,start,no=0;
ans=0;
for(i=from;i<=end;i++){
//if(com[i]=="ELSE") no++;
if(com[i]=='I') p++;
if(com[i]=='N') p--;
if(p==0){
no++;
}
}
//cout<<"no"<<no<<endl;
p=0;
if(no>1){
// cout<<"2**"<<endl;
start=1;
ans=1;
for(i=from;i<=end;i++){
if(com[i]=='I') p++;
if(com[i]=='N') p--;
if(p==0){
ans*=find(start,i);
start=i+1;
}
}
}
else{
// cout<<"1**"<<endl;
p=0;
for(i=from+1;i<=end-1;i++){
if(com[i]=='I' ) p++;
if(com[i]=='N') p--;
if(com[i]=='E' && p==0)
{
ans=find(from+1,i-1)+find(i+1,end-1);
break;
}
}
}
return ans;
}
int main(){
char a[30];
long long n,i;
cin>>n;
while(n--)
{
count1=0;
while(cin>>a){
if(strcmp(a,"ENDPROGRAM")==0) break;
if(a[0]!='S'){
count1++;
if(a[1]=='N')
com[count1]=a[1];
else com[count1]=a[0];
}
}
cout<<find(1,count1)<<endl;
}
//system("pause");
}
Input:
The correct output: 2.
Code: Select all
1
IF
END_IF
ENDPROGRAM
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact: