1 条题解
-
1
注意到min(p,q)<=1e6,不妨设p>q,那么先沿坐标轴走p最优
打个表:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 1 4 10 20 35 56 84 120 165 220 286 364 455 560 680 816 969 1140 1330 1540 1 5 15 35 70 126 210 330 495 715 1001 1365 1820 2380 3060 3876 4845 5985 7315 8855 1 6 21 56 126 252 462 792 1287 2002 3003 4368 6188 8568 11628 15504 20349 26334 33649 42504 1 7 28 84 210 462 924 1716 3003 5005 8008 12376 18564 27132 38760 54264 74613 100947 134596 177100 1 8 36 120 330 792 1716 3432 6435 11440 19448 31824 50388 77520 116280 170544 245157 346104 480700 657800 1 9 45 165 495 1287 3003 6435 12870 24310 43758 75582 125970 203490 319770 490314 735471 1081575 1562275 2220075 1 10 55 220 715 2002 5005 11440 24310 48620 92378 167960 293930 497420 817190 1307504 2042975 3124550 4686825 6906900 1 11 66 286 1001 3003 8008 19448 43758 92378 184756 352716 646646 1144066 1961256 3268760 5311735 8436285 13123110 20030010 1 12 78 364 1365 4368 12376 31824 75582 167960 352716 705432 1352078 2496144 4457400 7726160 13037895 21474180 34597290 54627300 1 13 91 455 1820 6188 18564 50388 125970 293930 646646 1352078 2704156 5200300 9657700 17383860 30421755 51895935 86493225 141120525 1 14 105 560 2380 8568 27132 77520 203490 497420 1144066 2496144 5200300 10400600 20058300 37442160 67863915 119759850 206253075 347373600 1 15 120 680 3060 11628 38760 116280 319770 817190 1961256 4457400 9657700 20058300 40116600 77558760 145422675 265182525 471435600 818809200 1 16 136 816 3876 15504 54264 170544 490314 1307504 3268760 7726160 17383860 37442160 77558760 155117520 300540195 56572272010371583201855967520 1 17 153 969 4845 20349 74613 245157 735471 2042975 5311735 13037895 30421755 67863915 145422675 300540195 601080390116680311022039614304059928950 1 18 171 1140 5985 26334 100947 346104 1081575 3124550 8436285 21474180 51895935 119759850 265182525 5657227201166803110233360622045375676508597496600 1 19 190 1330 7315 33649 134596 480700 1562275 4686825 13123110 34597290 86493225 206253075 471435600103715832022039614304537567650907513530017672631900 1 20 210 1540 8855 42504 177100 657800 2220075 6906900 20030010 54627300 141120525 347373600 8188092001855967520405992895085974966001767263190035345263800然后把电脑转一下发现他是杨辉三角。
答案就是:
然后组合数可以快速算,假设第C(p+i-1,i-1)=t,那C(p+i,i)=t*(p+i)/i
#include<bits/stdc++.h> #define int long long #define mod 1000000007 using namespace std; int p,q; int Pow(int a,int b){ int as=1,bs=a; while(b){ if(b&1)as=as*bs%mod; bs=bs*bs%mod;b>>=1; }return as; } signed main(){ cin>>p>>q; if(p<q){ swap(p,q); } int ans=p,t=1; for(int i=1;i<=q;++i){ t=t*((p+i)%mod)%mod*Pow(i,mod-2)%mod; ans=(ans+t)%mod; }cout<<ans<<"\n"; return 0; }
- 1
信息
- ID
- 261
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- (无)
- 递交数
- 19
- 已通过
- 5
- 上传者