您的位置:首页 > 其它

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
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: