| ||||||||||
| 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 | |||||||||
使用哈希叭 首先把20 20 20记住可以省不少时间#include <stdio.h>
typedef struct{
int a,b,c;
int value;
int k;
}node,* pnode;
int maxlen=100000;
node hash[100000];
int push(int a,int b,int c,int v)
{
int i=0;
int t;
while(t=(a+b*2+c*3+i)%maxlen,hash[t].k==1&&(hash[t].a!=a||hash[t].b!=b||hash[t].c!=c))
i++;
if(hash[t].k==1)
return v;
hash[t].a=a;
hash[t].b=b;
hash[t].c=c;
hash[t].value=v;
hash[t].k=1;
return v;
}
int find(int x,int y,int z)
{
int i=0;
int t;
while(t=(x+y*2+z*3+i)%maxlen,hash[t].k==1&&(hash[t].a!=x||hash[t].b!=y||hash[t].c!=z))
i++;
return t;
}
int w(int a,int b,int c)
{
int f=find(a,b,c);
if(hash[f].k==1)
return hash[f].value;
if(a<=0||b<=0||c<=0)
return push(a,b,c,1);
else if(a>20||b>20||c>20)
push(a,b,c,w(20,20,20)) ;
else if(a<b&&b<c)
return push(a,b,c,w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c));
else
return push(a,b,c,w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1));
}
void main()
{
int a,b,c,i;
for(i=0;i<maxlen;i++)
hash[i].k=0;
push(20,20,20,1048576);
while(scanf("%d%d%d",&a,&b,&c),a!=-1||b!=-1||c!=-1)
printf("w(%d, %d, %d) = %d\n",a,b,c,w(a,b,c));
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator