本文主要是介绍Gym 101612 Problem A. Auxiliary Project(DP),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:
用n个木棒凑成数字,和最大是多少
思路:
直接dp写。
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>typedef long long ll;
using namespace std;
const int maxn = 1e6 + 7;int dp[maxn];
int a[20];
void init() {a[0] = 6;a[1] = 2;a[2] = 5;a[3] = 5;a[4] = 4;a[5] = 5;a[6] = 6;a[7] = 3;a[8] = 7;a[9] = 6;
}int main() {freopen("auxiliary.in","r",stdin);freopen("auxiliary.out","w",stdout);init();int n;scanf("%d",&n);memset(dp,-1,sizeof(dp));dp[0] = 0;for(int i = 0;i <= n;i++) {if(dp[i] == -1) continue;for(int j = 0;j <= 9;j++) {dp[a[j] + i] = max(dp[a[j] + i],dp[i] + j);}}printf("%d\n",dp[n]);return 0;
}
这篇关于Gym 101612 Problem A. Auxiliary Project(DP)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!