[Explanations] CF1017D

Note that in this problem in very short string 01, the length of not more than 12, can be used to convert the set of integer representation, then open a two-dimensional array, about the pre-existence of all the strings inside and Wu maximum possible value queries on it.

1
int arr[i][v];

Specifically, a first array dimension may be converted to save a given string to an integer value of 01 $ I $, Wu when the second value is exactly equal to the answer at V $ $, then each processing line to interrogation, Wu will be less than the maximum value you can add up all the answers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

CF1017D namespace
{
class Program large column [explanations] CF1017D { public class Free Join { public static int [,] ARR; public static int [] CNT, wuVal; }
 





static void Main(string[] args)
{
string inp;string[] div;

int len, totTemp, totQuery, maxWu, x, _count;

inp = Console.ReadLine();div = inp.Split(' ');
len = Convert.ToInt32(div[0]);totTemp = Convert.ToInt32(div[1]);totQuery = Convert.ToInt32(div[2]);

Global.arr = new int[(1 << 13), 101];
Global.cnt = new int[1 << 13];
Global.wuVal = new int[len];

//read
inp = Console.ReadLine(); div = inp.Split(' ');
for(int i = 0; i < len; i++)
Global.wuVal[i] = Convert.ToInt32(div[i]);
for(int i = 0; i < totTemp; i++) {
inp = Console.ReadLine();
x = 0;
for(int j = 0; j < len; j++)
if(inp[j] == '1') x |= (1 << j);
Global.cnt[x]++;
}

//预处理
for(int i = 0; i < (1 << len); i++)
for(int j = 0; j < (1 << len); j++)
if(Global.cnt[i] > 0) {
x = 0; //代价
for(int k = 0; k < len; k++)
if((i & (1 << k)) == (j & (1 << k)))
x += Global.wuVal[k];
if(x <= 100) Global.arr[j, x] += Global.cnt[i];
}

while(totQuery-- > 0) {
inp = Console.ReadLine();div = inp.Split(' ');
maxWu = Convert.ToInt32(div[1]);

_count = x = 0;
for(int i = 0; i < len; i++)
if(inp[i] == '1') x |= (1 << i);

for(int i = 0; i <= maxWu; i++)
_count += Global.arr[x, i];
Console.WriteLine(_count.ToString());
}

}
}
}

Code that is the case, this question time cards very tight, cause I use C # tone for a long time or time out. After progressive translated into C ++ code on the AC.

Guess you like

Origin www.cnblogs.com/wangziqiang123/p/11696430.html