简单DP,N×M的网格其中有一条边坏掉了,问从起点到终点的放法数

有两种方法,一种是DP很好理解

 //#define LOCAL
#include <cstdio>
#include <cstring> int dp[][];
bool flag[][]; int main(void)
{
#ifdef LOCAL
freopen("2125in.txt", "r", stdin);
#endif int r, c;
while(scanf("%d%d", &r, &c) == )
{
int y1, x1, y2, x2;
scanf("%d%d%d%d", &y1, &x1, &y2, &x2);
dp[][] = ;
memset(flag, false, sizeof(flag));
flag[x1+][y1+] = flag[x2+][y2+] = true;
for(int i = ; i <= r; ++i)
for(int j = ; j <= c; ++j)
{
dp[i][j] = dp[i-][j] + dp[i][j-];
if(flag[i][j])
{
if(flag[i][j-])
dp[i][j] -= dp[i][j-];
if(flag[i-][j])
dp[i][j] -= dp[i-][j];
}
}
printf("%d\n", dp[r][c]);
}
return ;
}

代码君

第二种,用数学公式

如果没有坏边的话,总放法数是CN-1(M+N-2) 

因为每种方法都要走(M+N-2)步,向上走N-1步,向下走M-1步

现在考虑一条坏边,那么就计算经过这条坏边的方案数然后从总数里面减去即可

经过坏边的放法数就是从起点到(x1, y1)的放法数×从(x2, y2)到终点的放法数

 #define LOCAL
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std; long long c(long long m, long long n)
{
if(m== || n==)
return ;
n = min(n, m-n);
long long ans = ;
for(int i = ; i < n; ++i)
ans = ans * (m-i) / (+i);
return ans;
} int main(void)
{
#ifdef LOCAL
freopen("2125in.txt", "r", stdin);
#endif int n, m;
while(scanf("%d%d", &n, &m) == )
{
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
if(x1+y1 > x2+y2)
{
int t = x1;
x1 = x2, x2 = t;
t = y1;
y1 = y2, y2 = t;
}
printf("%lld\n", c(m+n-, m-) - c(x1+y1, x1) * c(m+n--x2-y2, m--x2));
}
return ;
}

代码君

HDU 2125 Local area network的更多相关文章

  1. Real-time storage area network

    A cluster of computing systems is provided with guaranteed real-time access to data storage in a sto ...

  2. (转)内置系统账户:Local system/Network service/Local Service 区别

    最近会转载一些 MSSQL 基础相关的文章. 参考文献: http://www.cnblogs.com/xianspace/archive/2009/04/05/1429835.html 前言 今天在 ...

  3. Local System/Network Service/Local Service

    // The name of the account under which the service should run// 1 NT AUTHORITY\\SYSTEM 2 NT AUTHORIT ...

  4. [转帖]内置系统账户:Local system/Network service/Local Service 区别

    内置系统账户:Local system/Network service/Local Service 区别 学习使用 xp_cmdshell 的时候 发现必须 sqlserver 的服务运行在local ...

  5. 存储区域网络(Storage Area Network,简称SAN)

    存储区域网络(Storage Area Network,简称SAN)采用网状通道(Fibre Channel ,简称FC,区别与Fiber Channel光纤通道)技术,通过FC交换机连接存储阵列和服 ...

  6. 内置系统账户:Local system/Network service/Local Service 区别

    参考文献: http://www.cnblogs.com/xianspace/archive/2009/04/05/1429835.html 前言 今天在安装sqlserver2008 r2的时候,在 ...

  7. 关于Local System/Local Service/Network Service账户

    部署或安装系统服务时需要指定服务运行的账户.一般地,可选择Local System.Local Service或Network Service账户. Local System/Local Servic ...

  8. linux 下使用 tc 模拟网络延迟和丢包-使用 linux 模拟广域网延迟 - Emulating wide area network delays with Linux

    tc 是linux 内置的命令:使用man pages 查看 我们看到,其功能为 show / manipulate traffic control settings,可对操作系统进行流量控制: ne ...

  9. Windows内置系统账户:Local system/Network service/Local Service 区别

    LocalSystem 账户  LocalSystem是预设的拥有本机所有权限的本地账户,这个账户跟通常的用户账户没有任何关联,也没有用户名和密码之类的凭证.这个服务账户可以打开注册表的HKEY_LO ...

随机推荐

  1. Unity3D战争迷雾效果

    原地址:http://liweizhaolili.blog.163.com/blog/static/16230744201431835652233/ 最近一直都在做Flash相关的东西,很久没有空搞U ...

  2. Eclipse提示Tomcat miss丢失bug:The Tomcat server configuration at \Servers\Tomcat v5.5 Server at localhost-config is missing.

    Eclipse提示Tomcat miss丢失bug:The Tomcat server configuration at \Servers\Tomcat v5.5 Server at localhos ...

  3. Android隐式启动匹配:action,category,data

    简介 Android开发中,Activity,Service 和 BroadcastReceiver 启动有两种方式,显示启动和隐式启动. 为方便下面描述,我以Activity启动为例. 显示启动便是 ...

  4. 306. Additive Number

    题目: Additive number is a string whose digits can form additive sequence. A valid additive sequence s ...

  5. 实际操作中命令 su 与 sudo 的区别(转)

    ------------------------------------------------------------------------------------------------ 首先我 ...

  6. 常用WinPE

    微PE工具箱:http://www.wepe.com.cn/ 绝对PE工具箱:http://dl.pconline.com.cn/download/64736.html 通用PE工具箱:http:// ...

  7. USACO Section 2.2: Party Lamps

    这题有个小技巧, 按一个键两次等于没按,所以如果depsum > 16的话其实不用做深搜到depsum次,而只要16次就可以了. /* ID: yingzho1 LANG: C++ TASK: ...

  8. Web Server 使用WebClient 发送https请求 The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

    使用WebClient 发送https请求 使用WebClient发送请求时,并且是以https协议: WebClient webClient = new WebClient(); string re ...

  9. Web Server tomcat配置网站

    tomcat配置网站 环境变量: 变量名:CATALINA_HOME 变量值:安装路径 1.在tomcat文件夹的conf"catalina"localhost(对于Tomcat6 ...

  10. AES加密和解密

    using System; using System.Security.Cryptography; using System.Text; using System.IO; namespace AES ...