FZU 2156 Climb Stairs
2015-09-10 00:22
369 查看
题目大意: 你要从0层开始, 经过A, 和B层, 到达N层, 每次可以走x或者y层, 输出方法数。
比较简单的dp了吧。。只是处理方式稍微机智点(虽然还是比较好想到的), 递推方程dp[i] = dp[i - x] + dp[i - y],然后输出dp[A] + dp[B - A] + dp[N - B],(事先swap保证A <= B) 。
比较简单的dp了吧。。只是处理方式稍微机智点(虽然还是比较好想到的), 递推方程dp[i] = dp[i - x] + dp[i - y],然后输出dp[A] + dp[B - A] + dp[N - B],(事先swap保证A <= B) 。
#include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <string> #include <cctype> #include <cstdio> #include <vector> #include <cstdlib> #include <cstring> #include <iomanip> #include <sstream> #include <iostream> #include <algorithm> using namespace std; #define ls id<<1,l,mid #define rs id<<1|1,mid+1,r #define OFF(x) memset(x,-1,sizeof x) #define CLR(x) memset(x,0,sizeof x) #define MEM(x) memset(x,0x3f,sizeof x) typedef long long ll ; typedef pair<int,int> pii ; const int maxn = 1e5+50 ; const int inf = 0x3f3f3f3f ; const int MOD = 1e9+7 ; ll dp[maxn]; int n, x, y, a, b; int main () { #ifdef LOCAL freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin); // freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout); #endif while (cin >> n >> x >> y >> a >> b) { CLR(dp); dp[0] = 1; for (int i = 1; i <= n; i++) { if (i >= x) dp[i] = (dp[i] + dp[i - x]) % MOD; if (i >= y) dp[i] = (dp[i] + dp[i - y]) % MOD; } if (a > b) swap(a, b); printf("%I64d\n", (dp[a] * dp[b - a]) % MOD * dp[n - b] % MOD); } return 0; }
相关文章推荐
- NSSearchPathForDirectoriesInDomains用法
- Get the date of the days before today on AIX
- HDU 1789 Doing Homework again
- 使用GCE(Google Container Engine)体验容器云服务 (1)
- VMware Containers - VMware vSphere Integrated Containers
- 游戏人工智能开发之6种决策方法
- Ubuntu下出现su:authentication failure的解决办法
- 快速去除图标斜线水印
- dnsmasq+postfix+sasl+tls+dovecot(邮件服务器)
- traits:Traits技术学习笔记
- cocos2d智能指针 转自:http://blog.csdn.net/nxshow/article/details/44699409
- hdu 2686 Matrix / 3376 Matrix Again最大费用流
- Waiting for table metadata lock问题的解决
- 第24/24周 数据库维护(Database Maintenance)
- 1090. Highest Price in Supply Chain (25)
- IBM AIX6.1上安装OpenSSH手记
- 查看某一个点是否在某个多边形内 使用ST_Contains函数
- error LNK2001: unresolved external symbol _main解决办法
- RTAI installation for Ubuntu 14.04
- Failed to add reference to 'System.Net.Http'. Please make sure that it is in the Global Assembly Cache.