题目链接:https://www.luogu.org/problemnew/show/P1666

10.13考试题

当时没想出来,觉得是要用trie做,在trie上跑一个树形dp

结果是写了个子集枚举还炸了

后来这道题可以暴力+string类型解

还是string用的少啊

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 100;
string a[maxn];
ll n, ans, f[maxn][maxn], dp[maxn];
bool check(int i, int j)
{
if(a[i].size() > a[j].size()) swap(i, j);
if(a[j].find(a[i]) != 0) return 1;
else return 0;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i = 1; i <= n; i++) cin>>a[i];
sort(a+1, a+1+n);
for(int i = 1; i <= n; i++)
{
dp[i] = 1;
for(int j = 1; j <= n; j++) f[i][j] = check(i, j);
}
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++)
if(f[i][j]) dp[j] += dp[i]; for(int i = 1; i <= n; i++)
ans += dp[i];
cout<<ans+1;
return 0;
}

【luogu P1666 前缀单词】 题解的更多相关文章

  1. 洛谷 P1666 前缀单词 题解

    题意:给n个单词,如果单词a为单词b的前缀则a,b不能共存,问能共存的集合数(包括空集) 一道dp题,排序后判断,f[i][j]表示i和j是否能共存,f[i][j]=1表示能共存,初始化dp[i]=1 ...

  2. Luogu P1666 前缀单词

    校内资格赛题目,差点高一就要\(\tt{AFO}\)了 30分思路 对30%的数据,满足$1≤n≤10 $ 所以我们可以子集枚举,实际得分40pts #include<iostream> ...

  3. P1666 前缀单词

    P1666 前缀单词 tire树上跑dp 首先将trie树建出来,然后对于每个节点.考虑他的子节点. 子节点的方案数都互不干扰,所以子节点与其他子节点的的方案数可以利用乘法原理算出来. 然后如果这个节 ...

  4. P1666前缀单词

    题目传送门点我传送 Ⅰ.字典树+树型DP 非常奇妙的一种解法 第一部分:构建树 先对来的单词读入,插入字典树 然后对于一颗字典树,其实是有很多无用边的,所以我们需要删去一些边 删去非单词节点和非单词节 ...

  5. luogu P1026 统计单词个数

    题目链接 luogu P1026 统计单词个数 题解 贪心的预处理母本串从i到j的最大单词数 然后dp[i][j] 表示从前i个切了k次最优解 转移显然 代码 #include<cstdio&g ...

  6. luogu P2353 背单词

    二次联通门 : luogu P2353 背单词 一眼看过去, 卧槽,AC自动机板子题 写完后T成SB 卧槽10^6 做个篮子啊 重构思路... 恩..Hash + 莫队... 恶心啊.. 找xxy d ...

  7. C#版(击败100.00%的提交) - Leetcode 151. 翻转字符串里的单词 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  8. [luogu]P1026 统计单词个数[DP][字符串]

    [luogu]P1026 统计单词个数 题目描述 给出一个长度不超过200的由小写英文字母组成的字母串(约定;该字串以每行20个字母的方式输入,且保证每行一定为20个).要求将此字母串分成k份(1&l ...

  9. 【洛谷 P1666】 前缀单词 (Trie)

    题目链接 考试时暴搜50分...其实看到"单词","前缀"这种字眼时就要想到\(Trie\)的,哎,我太蒻了. 以一个虚点为根,建一棵\(Trie\),然后\( ...

随机推荐

  1. 13. Roman to Integer 罗马数字转化为阿拉伯数字(indexOf ()和 toCharArray())easy

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  2. DataTables获取指定元素的行数据

    法1: 用jquey获取,var row = $('.edit').parent().parent(); 缺点:只能获取dom上的东西,不能获取没有渲染的数据 法2: 首先绑定行号到元素上 $('#e ...

  3. javaweb servlet jsp简单笔记

    第二章: 1: web 俗称 : 万维网  www 2: web开发 的三大核心: HTML(网页) ,URL(定位),HTTP:(协议) 页面的分类: 静态页面: html+css 动态页面:jsp ...

  4. csharp: QR Code Barcode

    /// <summary> /// /// </summary> /// <param name="sender"></param> ...

  5. URL传递中文:Server.UrlEncode与Server.UrlDecode

    1.设置web.config文件. <system.web>  ......  <globalization requestEncoding="gb2312" r ...

  6. python 数据结构应用

  7. centos系统移植

    今天将一个服务器上面的硬盘拆掉放到安装到另外一个服务器上面,硬盘里已经安装系统为centos6.0. 服务器 为dell的1850,好吧,在今天我还有幸搞这种“屎”前的服务器还是很幸运的! 硬盘换了之 ...

  8. leetcode Ch1-search 2014

    1. Search Insert Position class Solution { public: int searchInsert(int A[], int n, int target) { ,r ...

  9. incast.tcl

    # Basic Incast Simulation # Check Args if {$argc != 5} { puts "Usage: ns incast <srv_num> ...

  10. PowerShell管理Hyper-V(Windows2008R2)

    gwmi -list -namespace "root\virtualization" 在Windows2012R2之前的版本,Hyper-V管理都是用的root\virtuali ...