| ||||||||||
| 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 | |||||||||
why wa???#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
char b[33],s[33];
int a[40],d[40];
int binary(char *s)
{
int i,len,num=0;
len = strlen(s);
for(i = len-1;i >= 0;i--)
num += (s[i]-'0')*(int(pow(2.0,double(len - i - 1))));
return num;
}
int binomial (int n, int k)
{
int i;
if (n-k < k)
k = n-k;
double b = 1;
for(i=0 ; i<k ; i++)
b = (b * (n-i)) / (i+1);
return (int) floor (b);
}
int main()
{
int i,j,k,n,c,f,t,num,p1,p2,sum;
double ans;
while(scanf("%d",&n)&&n)
{
for(i = 1;i <= n;i++)
scanf("%d",&a[i]);
scanf("%d",&t);
for(i = 1;i <= t;i++)
{
scanf("%s",b);
num = binary(b);
// printf("num = %d\n",num);
for(j = 1;j <= n/2;j++)
{
scanf("%d",&c);
for(k = 1;k <= n;k++)
if(c == a[k])
break;
d[j] = k;
}
sort(d+1,d+n/2+1);
d[0] = 0;
f = 0;
for(j = 1;j <= n/2;j++)
{
if(d[j] - d[j-1] == 1)
sum = 0;
else
sum = d[j] - d[j-1];
for(k = 1;k < sum;k++)
{
ans = 1;
f +=binomial(n-k,n/2-j);
// for(p1 = n - k,p2 = 1;p1 >= n/2-k+j+1;p1--,p2++)
// ans = ans*p1/p2;
// f += ans;
}
}
if(f == num)
printf("TRUE\n");
else
printf("FALSE\n");
}
}
return 0;
}
/*
Sample Input
4
12 50 74 34
1
00
50 12
8
45 23 86 43 90 76 12 74
2
111001
86 43 90 74
010001
45 86 43 90
4
12 50 74 34
2
101
34 74
110
34 74
0
Sample Output
TRUE
TRUE
FALSE
TRUE
FALSE
*/
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator