bfs代码ac,不会背包dp QnQ
#include <bits/stdc++.h>
using namespace std;
bool vis[1000010];
int cnt[1000010];
queue<int> q;
int main()
{
int n;
cin >> n;
vis[0] = 0;
cnt[0] = 0;
q.push(0);
while (q.size())
{
int x = q.front();
q.pop();
if (x == n)
{
cout << cnt[n] << endl;
return 0;
}
int kx = x + 1;
if (kx <= n && !vis[kx])
{
vis[kx] = 1;
q.push(kx);
cnt[kx] = cnt[x] + 1;
}
kx = x + 5;
if (kx <= n && !vis[kx])
{
vis[kx] = 1;
q.push(kx);
cnt[kx] = cnt[x] + 1;
}
kx = x + 11;
if (kx <= n && !vis[kx])
{
vis[kx] = 1;
q.push(kx);
cnt[kx] = cnt[x] + 1;
}
}
return 0;
}