ACM-ICPC Asia Phuket Regional Programing Contest 2009----F: Your Ways

题目链接:http://acm.bnu.edu.cn/contest/problem_show.php?pid=4275

这个题实际不难,就是一个学生每天都会从(0,0)到(w,h),每天都会有一些道路不能走,求每天从起点到终点的种数,但比赛时却少有人去碰,原因是忽略了题目中最重要的一句话“The blocking is done in such a way that it is not possible to reach parts of the streets or avenues which is blocked from some other part which is blocked as well through any paths containing only West-to-East and South-to-North walks.”这对降低难度起到了至关重要的作用,意思是说每条道不能走的道路不会相互影响,赛后大家一起讨论时才发现了这一点.....- -||这道晃人的体就完全可在

600 Bytes之内解决了!

rookie的代码:

#include #define mod 2552 int t,w,h,k,aa,b,c,d,ans,num; int a[1010][1010]; int main() { scanf("%d",&t); while(t--){ scanf("%d%d%d",&w,&h,&k); for(int i=0;i<=(w>h?w:h);i++) a[0][i]=a[i][0]=1; for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) a[i][j]=(a[i][j-1]+a[i-1][j])%mod; for(int i=1;i<=k;i++){ ans=a[h][w]; scanf("%d",&num); for(int i=1;i<=num;i++){ scanf("%d%d%d%d",&aa,&b,&c,&d); ans-=a[b][aa]*a[h-d][w-c]; ans=(ans+mod)%mod; } if(ans<0)ans+=mod; printf("%d/n",ans); } } return 0; }

你可能感兴趣的:(ACM解题报告,c)