link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=615
和完全背包一样的思想。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
int a[]={,,,,};
int f[];
int main(void)
{
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int n;
while (cin>>n) {
memset(f,,sizeof(f)); f[]=;
for (int i = ; i < ; ++i) {
for (int j=a[i]; j<=n;++j) {
f[j]+=f[j-a[i]];
}
}
cout<<f[n]<<endl;
}
return ;
}
o(╯□╰)o
认真理解一下这种思想就行了。不难