hdu 2125 Local area network 简单dp之pair初体验

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

并不是什么难题,看一眼就知道的简单dp思想
想找个机会使用一下pair
然而这道其实没有必要使用
记一下pair语法
声明和赋值
pair<int ,int >p (5,6);
pair<int ,int > p1= make_pair(5,6);
pair<string,double> p2 (“aa”,5.0);
引用时.second
值得一提的是 pair 比较规则为
先比较first 再比较second
上代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
long long dp[45][45];
void print(int n,int m)
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
            printf("%lld ",dp[i][j]);
        cout<<endl;
    }
    cout<<endl;
    return ;
}
int main()
{

    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        int flag=0;//1 heng 2 shu
        pair<int,int>coor1,coor2,coor3;
        int tmp1,tmp2,tmp3,tmp4;
        scanf("%d%d%d%d",&tmp1,&tmp2,&tmp3,&tmp4);
        if(tmp1==tmp3) flag=1;
        else flag=2;
        coor1=make_pair(tmp1,tmp2);
        coor2=make_pair(tmp3,tmp4);
        coor3=max(coor1,coor2);
        //cout<<coor3.first<<endl;
        //cout<<coor3.second<<endl;
        dp[0][0]=1;
        for(int i=1; i<n; i++)
        {
            if(flag==1&&coor3.second==i&&coor3.first==0)
                dp[0][i]=0;
            else dp[0][i]=dp[0][i-1];
        }
        for(int i=1; i<m; i++)
        {
            if(flag==2&&coor3.first==i&&coor3.second==0)
                dp[i][0]=0;
            else dp[i][0]=dp[i-1][0];
        }
        if(m==1||n==1)
        {
            printf("%lld\n",dp[n-1][m-1]);
            continue;
        }
        for(int i=1; i<m; i++)
        {
            for(int j=1; j<n; j++)
            {
                if(coor3.first==i&&coor3.second==j)
                {
                    if(flag==1) dp[i][j]=dp[i-1][j];
                    else dp[i][j]=dp[i][j-1];
                }
                else dp[i][j]=dp[i-1][j]+dp[i][j-1];
            }
        }
        //print(n,m);
        printf("%lld\n",dp[m-1][n-1]);
    }
    return 0;
}
//caowenbo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值