Function Run Fun Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17843 Accepted: 9112 Description We all love recursion! Don't we? Consider a three-parameter recursive function w(a, b, c): if a <= 0 or b <= 0 or c <= 0, then w(a, b…
题目链接:http://poj.org/problem?id=1579 思路分析:题目给出递归公式,使用动态规划的记忆搜索即可解决. 代码如下: #include <stdio.h> #include <string.h> + ; int dp[MAX_N][MAX_N][MAX_N]; int w( int a, int b, int c ) { ) return dp[a][b][c]; || b <= || c <= ) ; else if ( a < b…
f(i,j,k)表示第i行,放的雷的状态为j{0表示不放,1表示往上放,2表示往下放,3表示上下都放},剩余还有k(0<=k<=2)个要放的方案数. 先给出我这个sb写的错误代码,死都没调出来.优越的做法在后面 #include<cstdio> #include<cstring> using namespace std; #define MOD 100000007 int T,n; char a[10010]; int f[10010][4][10]; int main…
典型的记忆化递归问题. 这类问题的记忆主要是利用数组记忆.那么已经计算过的值就能够直接返回.不须要进一步递归了. 注意:下标越界.递归顺序不能错,及时推断是否已经计算过值了,不要多递归. 或者直接使用动态规划法填好表也是能够的. #include <stdio.h> #include <limits.h> const int MAX_N = 21; int W[MAX_N][MAX_N][MAX_N]; int getValue(int a, int b, int c) { if…
可以暴力递归求解,应该不会TLE,但是我们考虑记忆化优化. 设f(i,j)表示第i个数为j时的方案数. f(i,j)=f(1,j-1)+f(2,j-1)+……+f(i-1,j-1) (4>=j>=1),从f(n,4)开始递归求解就行. 但是考虑到状态最多只有n*4种,所以记忆化掉吧. 初始化:f(i,1)=1 (1<=i<=n-3) #include<cstdio> using namespace std; int n; ][]; long long f(int cur…
跟CODEVS 3415没有什么区别,也不用高精度. http://www.cnblogs.com/autsky-jadek/p/4055184.html #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; ll n,dp[][][],ans=-; int m,wei,len;…
题目传送门:http://poj.org/problem?id=1579 Function Run Fun Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20560 Accepted: 10325 Description We all love recursion! Don't we? Consider a three-parameter recursive function w(a, b, c): if a <=…
A OpenJ_Bailian 1088 滑雪 B OpenJ_Bailian 1579 Function Run Fun C HDU 1078 FatMouse and Cheese D POJ 3280 Cheapest Palindrome E OpenJ_Bailian 1976 A Mini Locomotive F OpenJ_Bailian 2111 Millenium Leapcow G OpenJ_Bailian 1141 B…
Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8990 Accepted: 2004 Description Mr.Dog was fired by his company. In order to support his family, he must find a new job as soon as possible. Nowadays, It's hard to have a job…