题目链接:https://www.tyvj.cn/Problem_Show.aspx?id=1014 f[i][j]表示区间[i,j]所得到的最小值. 不断地划分区间,把结果保存起来. #include <cstdio> #include <cstdlib> #include <algorithm> using namespace std; ][];], i, j, n, INF=0x7f7f7f7f; void dfs(int l, int r) { ) {f[l][…
题目传送门 /* 记忆化搜索(DP+DFS):dp[i][j] 表示第i到第j个字符,最少要加多少个括号 dp[x][x] = 1 一定要加一个括号:dp[x][y] = 0, x > y; 当s[x] 与 s[y] 匹配,则搜索 (x+1, y-1); 否则在x~y-1枚举找到相匹配的括号,更新最小值 */ #include <cstdio> #include <algorithm> #include <cmath> #include <iostream&…
直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记忆化搜索的方式进行DP,成功避免重叠子问题,避免超时 #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<algorithm> #include…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1331 Function Run Fun Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3459    Accepted Submission(s): 1707 Problem Description We all love recursio…
Solution 注意取模!!! Code #include<bits/stdc++.h> #define mod 1000000007 #define LL long long using namespace std; int n, a, b; LL mpow(LL a, LL b) { LL ans = ; , a = a * a % mod) ) ans = ans * a % mod; return ans; } LL fac[], inv[], l[], t[]; void init…
这两题是一模一样的``` 题意:给了一系列递推关系,但是由于这些递推很复杂,所以递推起来要花费很长的时间,所以我要编程序在有限的时间内输出答案. w(a, b, c): 如果a,b,c中有一个值小于等于0,那么w(a, b, c)的值为1 如果a,b,c中有一个值大于20,那么w(a, b, c)的值为w(20, 20, 20) 如果a<b<c,那么w(a, b, c)=w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c) 否则w(a, b, c)=w(a-…
点我进入题目 题目大意:n个小孩围一圈传球,每个人可以给左边的人或右边的人传球,1号小孩开始,一共传m次,请问有多少种可能的路径使球回到1号小孩. 输入输出:输入n,m,输出路径的数量. 数据范围:40% 3<=n<=30 1<=m<=20 100% 3<=n<=30 1<=m<=30 我是这么想的:膜拟过程,从1号小孩开始dfs,然后加一个记忆化搜索节省时间. dfs(num,tim)表示球传到第num个小孩,已经传过tim次时候,d[num][tim]表…
Rikka with Nash Equilibrium Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1460    Accepted Submission(s): 591 Problem Description Nash Equilibrium is an important concept in game theory. Ri…
Another OCD Patient Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 490    Accepted Submission(s): 180 Problem Description    Xiaoji is an OCD (obsessive-compulsive disorder) patient. This mo…
挤挤更健康 Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 339, Accepted users: 216 Problem 10086 : No special judgement Problem description 用边长小于N的正方形方砖(注意,不要求所有的方砖大小相同,请看样例说明)不重叠地铺满N*N的正方形房间,最少要几块方砖. Input 第一行是一个整…