Codeforces Round #313
2015-07-26 00:22
281 查看
A. Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimumunfortunate sum?
Input
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion.
The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Output
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
Sample test(s)
input
output
大水,没什么好说的。显然只要有1就能凑出所有数字,没有1就凑不出1,1就是那个最小的
B. Gerald is into Art
两个矩形能不能不重叠的放入第三个中。
暴力枚举一下放的方式
写的比较丑
View Code
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimumunfortunate sum?
Input
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion.
The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Output
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
Sample test(s)
input
5 1 2 3 4 5
output
-1
大水,没什么好说的。显然只要有1就能凑出所有数字,没有1就凑不出1,1就是那个最小的
B. Gerald is into Art
两个矩形能不能不重叠的放入第三个中。
暴力枚举一下放的方式
写的比较丑
#include <bits/stdc++.h> using namespace std; typedef __int64 ll; const int N = 2004; const int M = 200004; const int MOD = 1000000007; struct point{ int x, y; point(){}; point(int _x, int _y){x = _x, y = _y;}; void scan(){ scanf("%d%d", &x, &y); } bool operator<(const point &I)const{ if(x == I.x) return y < I.y; return x <I.x; } }p ; ll dp ; ll fac[M], inv[M]; ll quickpow(ll base, int p){ ll ans = 1; while(p){ if(p&1){ ans = ans * base % MOD; } base = base * base % MOD; p >>= 1; } return ans; } ll cal(int x, int y){ return fac[x+y]*inv[x]%MOD*inv[y]%MOD; } int main(){ int h, w, n, i, j, m; scanf("%d%d%d", &h, &w, &n); for(i = 1; i <= n; i++){ p[i].scan(); } p[++n] = point(h, w); sort(p + 1, p + n + 1); m = h + w; fac[0] = 1; inv[0] = 1; for(i = 1; i <= m; i++){ fac[i] = fac[i-1]*i%MOD; inv[i] = quickpow(fac[i], MOD-2); } for(i = 1; i <= n; i++){//printf("%I64d\n", dp[i]); dp[i] = cal(p[i].x-1, p[i].y-1); for(j = 1; j < i; j++){ if(p[j].y <= p[i].y){ dp[i] = ((dp[i] - dp[j]*cal(p[i].y-p[j].y, p[i].x-p[j].x)%MOD)%MOD + MOD) % MOD; } } } printf("%I64d\n", dp ); return 0; }
View Code
相关文章推荐
- 05-图2. Saving James Bond - Easy Version (25)
- uva 1379(dp)
- 关于jdk的并发集合
- Android触摸机制
- linux下的软件管理器之DPKG
- Nodejs总结
- C语言int类型指针指向char类型变量简单实例
- redis(五)-redis.conf
- 关于指针的++
- GeekBand第二周线下课堂
- JS 父窗口向子窗口传值问题(window.open())
- 又来折腾啦
- 第一百一十四天 how can I 坚持
- ListView的adapter中getView方法一直调用
- Android Framework 记录之一
- 关于Github 的 Watch , Star和Fork
- 一个全新的开始。
- iOS8 SDK新特性之扩展详解
- [LeetCode]Kth Smallest Element in a BST
- Android 向下弹出式对话框