ACM-ICPC 2017 Asia Xi'an J LOL 【暴力 && 排列组合】

任意门:https://nanti.jisuanke.com/t/20750

J - LOL

5 friends play LOL together . Every one should BAN one character and PICK one character . The enemy should BAN 55 characters and PICK 55 characters . All these 2020 heroes must be different .

Every one can BAN any heroes by his personal washes . But he can only PICK heroes which he has bought .

Suppose the enemy can PICK or BAN any heroes. How many different ways are there satisfying the conditions?

For example , a valid way is :

Player 11 : picks hero 11, bans hero 22

Player 22 : picks hero 33, bans hero 44

Player 33 : picks hero 5, bans hero 66

Player 44 : picks hero 77, bans hero 88

Player 55 : picks hero 99, bans hero 1010

Enemies pick heroes 11,12,13,14,1511,12,13,14,15 , ban heroes 16,17,18,19,2016,17,18,19,20 .

Input

The input contains multiple test cases.(No more than 2020)

In each test case . there’s 55 strings S[1] \sim S[5]S[1]S[5] ,respectively whose lengths are 100100 , For the ii-th person if he has bought the jj-th hero, the jj-th character of S[i]S[i] is '11', or '00' if not. The total number of heroes is exactly 100100 .

Output

For each test case , print the answer mod 10000000071000000007 in a single line .

样例输入复制
0110011100011001001100011110001110001110001010010111111110101010010011010000110100011001001111101011
1000111101111110110100001101001101010001111001001011110001111110101000011101000001011100001001011010
0100101100011110011100110110011100111100010010011001111110101111111000000110001110000110001100001110
1110010101010001000110100011101010001010000110001111111110101010000000001111001110110101110000010011
1000010011111110001101100000101001110100011000111010011111110110111010011111010110101111011111011011
样例输出复制
515649254

题意概括:

五个二进制数代表我方 5 人所拥有的英雄,0为没有,1为有。

敌方5人什么英雄都有,问有多少种 Ban Pick方案。

每人都可以选一个自己拥有的英雄和 ban 掉任何一个英雄,最后选的和禁止掉的20个英雄都不相同。

解题思路:

暴力枚举我方选英雄的方案

敌方选英雄的方案为 A(95, 5)

我方禁英雄的方案为 C(90, 5)

敌方禁英雄的方案为 C(85,5)

关于暴力的优化和剪枝:

如果是传统暴力枚举每个人选不同英雄的方案,需要五层 for(0, 100) 循环,TL!

优化只枚举前四个人的方案, 第五个能选的英雄只能是前面没有选的,缩小了一层循环。

关于剪枝 前面选过的不要选咯

 

AC code:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <cstring>
 5 #define INF 0x3f3f3f3f
 6 #define LL long long
 7 using namespace std;
 8 const int mod = 1e9+7;
 9 const int MAXN = 105;
10 
11 char a[MAXN], b[MAXN], c[MAXN], d[MAXN], e[MAXN];
12 LL A(LL N, LL R)
13 {
14     LL sum = 1;
15     for(int i = 0; i < R; i++)
16         sum *= N-i;
17     return sum;
18 }
19 
20 LL C(LL N, LL R)
21 {
22     LL sum = 1;
23     for(int i = 1; i <= R; i++)
24         sum = sum* (N+1-i)/i;
25     return sum;
26 }
27 
28 int main()
29 {
30     while(~scanf("%s%s%s%s%s", a, b, c, d, e)){
31         int len = 0;
32         for(int i = 0; i < 100; i++){
33             if(e[i] == '1') len++;
34         }
35         LL ans = 0;
36         for(int i = 0; i < 100; i++){
37             if(a[i] == '0') continue;
38             for(int j = 0; j < 100; j++){
39                 if(b[j] == '0' || j == i) continue;
40                 for(int k = 0; k < 100; k++){
41                     if(c[k] == '0' || k == i || k == j) continue;
42                     for(int p = 0; p < 100; p++){
43                         if(d[p] == '0' || p == i || p == j || p == k) continue;
44                         int res = len;
45                         if(e[i] == '1') res--;
46                         if(e[j] == '1') res--;
47                         if(e[k] == '1') res--;
48                         if(e[p] == '1') res--;
49                         if(res>=0)      ans+=res;
50                     }
51                 }
52             }
53         }
54         ans = ans*A(95, 5)%mod*C(90, 5)%mod*C(85, 5)%mod;
55         printf("%lld\n", ans);
56     }
57     return 0;
58 }
View Code

 

转载于:https://www.cnblogs.com/ymzjj/p/9865969.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ACM-ICPC(国际大学生程序设计竞赛)是一项面向大学生的计算机编程竞赛,涉及算法和数据结构等领域。在比赛中,选手需要解决一系列编程问题,使用合适的算法和数据结构来实现正确和高效的解决方案。 对于整理ACM-ICPC模板,以下是一些建议: 1. 了解比赛要求:首先,你需要了解ACM-ICPC比赛的具体要求和规则。这包括了解比赛所涉及的算法和数据结构,以及题目的类型和难度等。 2. 收集资料:收集与ACM-ICPC相关的资料,包括经典算法和数据结构的实现代码、常见问题的解题思路等。可以参考教材、博客、论文等资源。 3. 整理模板:将收集到的资料整理成模板。可以按照算法和数据结构的分类进行整理,例如排序算法、图算法、字符串算法等。对每个模板,添加必要的注释和示例代码,以便理解和使用。 4. 测试代码:对每个模板编写测试代码,确保它们的正确性和可靠性。可以使用已知的测试用例或自行设计测试用例。 5. 更新与扩充:定期更新和扩充模板,以适应ACM-ICPC比赛中新出现的算法和数据结构。同时,根据自己的经验和理解,对模板进行优化和改进。 6. 练习和复习:在比赛之前,利用整理好的模板进行练习和复习。尝试解决一些经典问题,使用模板中的算法和数据结构进行实现,并进行优化。 希望这些建议对你整理ACM-ICPC模板有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值