FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)

http://acm.fzu.edu.cn/contest/list.php?cid=152

 

主要是a题, lucas定理, 就这一版能过..  记录一下代码, 另外两个最短路  一个模拟,没什么记录价值.

 

 1 //#define txtout
 2 //#define debug
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<algorithm>
 7 #include<queue>
 8 #define mt(a,b) memset(a,b,sizeof(a))
 9 using namespace std;
10 typedef long long LL;
11 const double pi=acos(-1.0);
12 const double eps=1e-8;
13 const int inf=0x3f3f3f3f;
14 //const int M=1e7+10;
15 
16 LL pow_mod (LL a, LL n, LL p) {
17     LL ans = 1,t = a;
18     while (n) {
19         if (n & 1) {
20             ans = ans * t % p;
21         }
22         t = t * t % p;
23         n >>= 1;
24     }
25     return ans;
26 }
27 LL cal (LL n, LL m, LL p) {
28     if(m > n-m) m = n - m;
29     LL ans = 1;
30     for (int i = 1; i <= m; i++) {
31         ans = ans * (n - i + 1) % p;
32         int a = pow_mod(i,p-2,p);
33         ans = ans * a % p;
34     }
35     return ans;
36 }
37 LL com_mod (LL n,LL m,LL p) {
38     if (n < m)return 0;
39     return cal(n,m,p);
40 }
41 LL lucas (LL n, LL m, LL p) {
42     LL r = 1;
43     while(n && m && r) {
44         r = r *com_mod(n%p, m%p, p) % p;
45         n /= p;
46         m /= p;
47     }
48     return r;
49 }
50 
51 LL a,d,m,n;
52 //int c[M];
53 //LL C(int n,int m) {
54 //    LL result=1;
55 //    for(int i=0; i<m; i++) {
56 //        result*=(n-i);
57 //    }
58 //    for(int i=0; i<m; i++) {
59 //        result/=(1+i);
60 //    }
61 //    return result;
62 //}
63 const LL MOD=1000000007;
64 LL solve() {
65     if(n==1){
66         return a;
67     }
68     LL answer=lucas(m+n-1,n-1,MOD)*a%MOD;
69     if(n-2>=0) answer+=lucas(m+n-1,n-2,MOD)*d%MOD;
70     answer%=MOD;
71     return answer;
72 }
73 int main() {
74 #ifdef txtout
75     freopen("in.txt","r",stdin);
76     freopen("out.txt","w",stdout);
77 #endif // txtout
78 //    num=sieve(MAXN);
79     while(~scanf("%I64d%I64d%I64d%I64d",&a,&d,&m,&n)) {
80         printf("%I64d\n",solve());
81     }
82     return 0;
83 }
View Code

 

 

 

end

posted on 2016-08-17 17:10  gaolzzxin  阅读(237)  评论(0编辑  收藏  举报