hdu 2125 Local area network

ACM比赛整理

共 2712字,需浏览 6分钟

 · 2021-10-01

Local area network

Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1152    Accepted Submission(s): 388


Problem Description

A local area network (LAN) supplies networking capability to a group of computers in close proximity to each other such as in an office building, a school, or a home. A LAN is useful for sharing resources like files, printers, games or other applications. A LAN in turn often connects to other LANs, and to the Internet or other WAN.
In this contest, everybody is connecting with each others like the following figure.



The contest’s network was built as N rows and M columns, your computer locate at (0, 0) and the judger’s computer locate at (m-1, n-1) The code you submit would only transfer to up or right smoothly. It doesn’t matter if some accidents happened. Could you tell me how many ways from your computer to judger when a data wire was broken?

 


Input

There are multiple cases. Every case contains two integers in the first line, N, M (3<=N+M<=40). Second line contains four integers X1, Y1, X2, Y2 (0<=X1, X2<M, 0<=Y1, Y2<N, |X1+Y1-X2-Y2|=1), meaning the broken wire position.

 


Output

Print the answer in one line.

 


Sample Input

3 3
0 0 1 0

 


Sample Output

3


局域网


问题描述

局域网(LAN)为办公大楼、学校或家庭等相距很近的一组计算机提供联网能力。局域网对于共享文件、打印机、游戏或其他应用程序等资源非常有用。一个局域网通常反过来连接到其他局域网,并连接到因特网或其他广域网。

在这次比赛中,每个人都像下图一样互相联系。

竞赛的网络由N行M列组成,你的计算机位于(0,0),评委的计算机位于(M -1, N -1)。你提交的代码只能顺利地向上或向右传输。即使发生了一些事故也没关系。你能告诉我你的电脑有多少种方法来判断数据线什么时候断了吗?


输入

有多种情况。每个case在第一行包含两个整数,N, M (3<=N+M<=40)。第二行包含四个整数X1, Y1, X2, Y2 (0<=X1, X2


输出

用一行打印答案。


Sample Input

3 3
0 0 1 0


Sample Output

3



代码:

#include"stdio.h"
#include"string.h"
int main()
{
int n,m;
int dp[50][50];
int i,l;
int x,y,flag;
int x1,y1,x2,y2;
while(scanf("%d%d",&n,&m)!=-1)
{
scanf("%d%d%d%d",&y1,&x1,&y2,&x2);
if(x1+y1>x2+y2)
{
x=x1;
y=y1;
}
else
{
x=x2;
y=y2;
}
if(x1!=x2)
flag=-1;
else
flag=1;
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(l=1;l<m;l++)
{
if(x==0 && l==y)
dp[0][l]=0;
else
dp[0][l]=dp[0][l-1];
}
for(i=1;i<n;i++)
{
for(l=0;l<m;l++)
{
if(i==x && l==y)
{
if(l!=0)
{
if(flag==-1)
dp[i][l]=dp[i][l-1];
else
dp[i][l]=dp[i-1][l];
}
else
{
if(flag==-1)
dp[i][l]=0;
else
dp[i][l]=dp[i-1][l];
}
}
else
{
if(l==0)
dp[i][l]=dp[i-1][l];
else
dp[i][l]=dp[i-1][l]+dp[i][l-1];
}
}
}
printf("%d\n",dp[n-1][m-1]);
}
return 0;
}


浏览 20
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报