首页 > 代码库 > luogu P3799 妖梦拼木棒
luogu P3799 妖梦拼木棒
二次联通门 : luogu P3799 妖梦拼木棒
/* luogu P3799 妖梦拼木棒 用一个桶存下所有的木棒 美剧两根短的木棒长度 后随便乘一乘就 好了。。 */ #include <algorithm> #include <cstdio> #define Mod 1000000007 #define Max 5000 void read (int &now) { now = 0; register char word = getchar (); while (word < ‘0‘ || word > ‘9‘) word = getchar (); while (word >= ‘0‘ && word <= ‘9‘) { now = now * 10 + word - ‘0‘; word = getchar (); } } int N; long long count[Max << 1]; long long Answer; int main (int argc, char *argv[]) { read (N); int x; for (register int i = 1; i <= N; i ++) { read (x); count[x] ++; } for (register int i = 1; i <= Max; i ++) for (register int j = i; j <= Max; j ++) { if (i + j > Max) break; if (i == j) { if (count[i] >= 2 && count[i << 1] >= 2) Answer = (Answer + count[i] * (count[i] - 1) / 2LL % Mod * (count[i << 1] * (count[i << 1] - 1) / 2 % Mod)) % Mod; } else if (count[i] >= 1 && count[j] >= 1 && count[i + j] >= 2) Answer = (Answer + (count[i] * count[j] % Mod * (count[i + j] * (count[i + j] - 1) / 2)% Mod)) % Mod; } printf ("%lld", Answer); return 0; }
luogu P3799 妖梦拼木棒
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。