标签:组合数 main logs -- class 前缀和 cpp 前缀 tag
tags:[组合][预处理]
题解:
关于方程A+C+B=X的正整数解组数。
我们用插板法可知,解的组数=在(X-1)个元素中选择两个元素的方案数
故答案为:C(x-1,2)+C(x,2)+C(x+1,2)+...+C(y-1,2)。
因为有多组样例,所以预处理好前缀和即可。
code:
#include <iostream> using namespace std; typedef long long LL; const int NICO = 1000000 + 10; const int MOD = 1000000007; int T, x, y; LL res = 0; LL ans[NICO]; int main() { cin >> T; for(int i=1;i<NICO;i++) { ans[i] = ans[i-1] + (LL)i * (i-1) / 2; ans[i] %= MOD; } while(T--) { cin >> x >> y; x = max(0, x-1); y = max(0, y-1); res = (ans[y]-ans[max(x-1,0)]+MOD)%MOD; cout << res << endl; } }
标签:组合数 main logs -- class 前缀和 cpp 前缀 tag
原文地址:http://www.cnblogs.com/RUSH-D-CAT/p/6395816.html