1. 程式人生 > >關於dp和記憶化搜尋

關於dp和記憶化搜尋

dp的的轉移,可以看成列舉所有情況,再加上列舉所有轉移方式,得到轉移結果.
而記憶化搜尋,其實就是一種深搜式的帶剪枝dp,我傻逼一樣的深搜,其實只是暴力列舉,蠢的一匹.
掛上來把

/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <string> #include <cmath> #include <bitset> #include <iomanip> #include <set> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define MP make_pair #define MT make_tuple #define PB push_back #define gcd __gcd #define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int > pii; typedef pair<LL,LL> pll; typedef pair<double,double > pdd; typedef pair<double,int > pdi; const int INF = 0x7fffffff; const LL INFF = 0x7f7f7f7fffffffff; const int MAXM = 5e3+17; const int MOD = 998244353
; const int MAXN = 3e3+17; LL ans = 0; int n,x,k,id = 0; void dfs(int now,int be,int lft) { ans = (ans+1)%MOD; if(be+1<k&&lft>=now) { dfs(now,be+1,lft-now); } //debug(lft);debug(ans); for (int i = now+1; i <= lft ; ++i) { dfs(i, 1, lft-i); // vec.pop_back(); } } int main(int argc, char const *argv[]) { #ifdef GoodbyeMonkeyKing freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout); #endif cin>>n>>x>>k; for (int i = x; i <= n ; ++i) { //vector<int > vec; //vec.push_back(i); dfs(i,1,n-i); } cout<<ans<<endl; return 0; }