牛客NOIP暑期七天营-提高组2
第一题:ACGT 题目链接: https://ac.nowcoder.com/acm/contest/931/A trie树、hash、map遍历 ①、trie树上的节点多记一个rest值表示还有多少个串没被用。枚举所有串, 每次先在trie上跑匹配串,看一看那个点的rest。如果没法匹配的话就往trie里插入原串,把结束节点的rest+1 ②、思路和trie类似。其实就是把trie换成hash。(把在树上跑换成去hash值) ③、将每个序列的个数存下,每次读入时判断对应序列的map的权值是否为0,若不为0,将输入序列和其对应序列的map权值-- ,ans++ 下面是第三种解法 : 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define inf 0x3f3f3f 5 ll read() 6 { 7 ll res=0,flag=0; 8 char ch; 9 if((ch=getchar())=='-')flag=1; 10 else if(ch>='0'&&ch<='9')res=ch-'0'; 11 while((ch=getchar())>='0'&&ch<='9')res=res*10+(ch-'0'); 12 return flag?-res:res;