leetcode 691. Stickers to Spell Word(状压dp)
来源:互联网 发布:pc围棋软件 编辑:程序博客网 时间:2024/06/07 10:44
题目:https://leetcode.com/contest/leetcode-weekly-contest-53/problems/stickers-to-spell-word/#
题意:给你n个stickers串,然后让你拼出target串(所谓拼出,就是删除一些字符后重组成target),让求拼出target的最小stickers数目
思路:状压dp
代码:
#include<bits/stdc++.h>using namespace std;#define ms1(X) memset((X), -1, sizeof((X)))#define SZ(X) ((int)(X).size())int dp[1<<16];class Solution {public: int minStickers(vector<string>& s, string t) { int m = SZ(t); ms1(dp); dp[0] = 0; for(int st = 0;st < (1<<m);st++){ if(dp[st] == -1) continue; for(int i = 0;i < s.size();i++){ int now = st; for(int j = 0;j < s[i].size();j++){ for(int k = 0;k < m;k++){ if(((now >> k) & 1) == 1) continue; if(t[k] == s[i][j]){ now |= 1<<k; break; } } } if(dp[now] == -1 || dp[now] > dp[st] + 1) dp[now] = dp[st] + 1; } } return dp[(1<<m)-1]; }};
阅读全文
0 0
- leetcode 691. Stickers to Spell Word(状压dp)
- leetcode 691.Stickers to Spell Word
- 691. Stickers to Spell Word
- leetcode -- 691. Stickers to Spell Word【动态规划 + 位图使用】
- LWC 53:691. Stickers to Spell Word
- leetcode691 Stickers to Spell Word 带记忆功能的回溯
- Stickers to Spell Word:多个单词拆拼接成完整以个目标单词所耗最小数目
- URALive 6510 Stickers(dp啊)
- LeetCode:Word Break(DP)
- LeetCode:Word Break II(DP)
- Leetcode 139 - Word Break(线性dp)
- LeetCode Word Break (dp)
- Leetcode dp Word Break
- 【Leetcode】Word Break (DP)
- [leetcode][DP] Word Break
- [LeetCode.DP]Word Break ||
- LeetCode Word Break DP
- leetcode---word-break---dp
- android-ANR的解析
- leetcode 694. Number of Distinct Islands(BFS)
- SpringMVC的工作流程
- Quartz-Calendar 排除指定节假日时间执行任务
- 算法第五次作业
- leetcode 691. Stickers to Spell Word(状压dp)
- JVM性能调优监控工具jps、jstack、jmap、jhat、jstat使用详解
- web 基础(一) 简介及HTML
- NIO方式实现文件的快速拷贝
- 微信小程序组件(六)form
- ERROR LNK2019:无法解析的外部的符号 _sscanf或者_vsprintf
- 卷积神经网络基础
- 用C语言实现两个链表查集
- Hash表(一)------原理解析