返回顶部

01背包模板

UVA11137

题意:

把n拆成立方和的形式

solution:

把立方看成权值

运用递推求解01背包

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<vector>
 5 #include<queue>
 6 #include<cstring>
 7 #define mp make_pair
 8 #define pb push_back
 9 #define first fi
10 #define second se
11 #define pw(x) (1ll << (x))
12 #define sz(x) ((int)(x).size())
13 #define all(x) (x).begin(),(x).end()
14 #define rep(i,l,r) for(int i=(l);i<(r);i++)
15 #define per(i,r,l) for(int i=(r);i>=(l);i--)
16 #define FOR(i,l,r) for(int i=(l);i<=(r);i++)
17 #define eps 1e-9
18 #define PIE acos(-1)
19 #define cl(a,b) memset(a,b,sizeof(a))
20 #define fastio ios::sync_with_stdio(false);cin.tie(0);
21 #define lson l , mid , ls
22 #define rson mid + 1 , r , rs
23 #define ls (rt<<1)
24 #define rs (ls|1)
25 #define INF 0x3f3f3f3f
26 #define LINF 0x3f3f3f3f3f3f3f3f
27 #define freopen freopen("in.txt","r",stdin);
28 #define cfin ifstream cin("in.txt");
29 #define lowbit(x) (x&(-x))
30 #define sqr(a) a*a
31 #define ll long long
32 #define ull unsigned long long
33 #define vi vector<int>
34 #define pii pair<int, int>
35 #define dd(x) cout << #x << " = " << (x) << ", "
36 #define de(x) cout << #x << " = " << (x) << "\n"
37 #define endl "\n"
38 using namespace std;
39 //**********************************
40 const int maxn=1e5+7;
41 int n;
42 ll cube[22];
43 ll dp[maxn];
44 //**********************************
45 void Init()
46 {
47     FOR(i,1,21)cube[i]=i*i*i;
48     cl(dp,0);dp[0]=1;
49 }
50 //**********************************
51 int main()
52 {
53     Init();
54     FOR(i,1,21)rep(j,cube[i],maxn)dp[j]+=dp[j-cube[i]];
55     while(cin>>n)cout<<dp[n]<<endl;
56     return 0;
57 }
View Code

 

posted @ 2018-09-21 11:11  牛奶加咖啡~  阅读(160)  评论(0编辑  收藏  举报