Light OJ 1013 Love Calculator(DP)】的更多相关文章

题目大意: 给你两个字符串A,B 要求一个最短的字符串C,使得A,B同时为C的子串. 问C最短长度是多少? C有多少种? 题目分析: 做这道题目的时候自己并没有推出来,看了网上的题解. 1.dp[C串的长度][包含A的字符个数][包含B的字符个数] = 种类数 状态转移:如果 A[i] == B[j] 那么 dp[k][i][j] = dp[k-1][i-1][j-1]. 就是说我最后一个字符是相同的那么我只要放一个就可以了. 如果 A[i] !=  B[j] 那么 dp[k][i][j] =…
1013 - Love Calculator Yes, you are developing a 'Love calculator'. The software would be quite complex such that nobody could crack the exact behavior of the software. So, given two names your software will generate the percentage of their 'love' ac…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1013 题意: 给你两个字符串,让你构造出一个长度最小的字符串,且它的子序列包含这两个字符串.问它的长度,和多少种情况. 思路: 长度的话就是lena + lenb - LCS,这个比较明显.情况数比较难算. dp[i][j][k]表示a字符串前i个字符 b字符串前j个字符构成长度为k的字符串有多少种情况. (1)a[i] == b[i] 就是dp[i][j][k] = dp[…
题目链接 http://lightoj.com/volume_showproblem.php?problem=1031 Description You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more nu…
http://www.lightoj.com/volume_showproblem.php?problem=1005        PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move…
思路:典型的数位DP!!! dp[i][j][k]:第i位,对mod取余为j,数字和对mod取余为k. 注意:由于32位数字和小于95,所以当k>=95时,结果肯定为0. 这样数组就可以开小点,不会超内存!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<vector> #include<cstring>…
题目大意: 给你一个N和K要求确定有多少种放法,使得没有两个车在一条线上. N*N的矩阵, 有K个棋子. 题目分析: 我是用DP来写的,关于子结构的考虑是这样的. 假设第n*n的矩阵放k个棋子那么,这个推导过程如下.   当我们们第n*n的矩阵的时候可以考虑第(n-1)*(n-1)的矩阵经过哪些变换可以变成n*n的. 如上图蓝色方格.我们加入蓝色方格之后,矩阵就会增大一圈. 1.加入我们蓝色方格不放置棋子. dp[n-1][k] 2.加入蓝色方格放置一枚棋子,那么我们其实有三种位置可以放置:(1…
#include <iostream> #include <cstdlib> #include <cstring> #include <queue> #include <cstdio> #include <algorithm> #include <map> //#include <time.h> //#include <ext/pb_ds/assoc_container.hpp> //#includ…
#include <iostream> #include <cstdlib> #include <cstring> #include <queue> #include <cstdio> #include <algorithm> #include <map> //#include <time.h> //#include <ext/pb_ds/assoc_container.hpp> //#includ…
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 这里可能有环 所以要缩点 可是看例子又发现 一个强连通分量可能要拆分 n最大才15 所以就状态压缩 将全图分成一个个子状态 每一个子状态缩点 求最小路径覆盖 这样就攻克了一个强连通分量拆分的问题 最后状态压缩DP求解最优值 #include <cstdio…