这是自己写的,求大佬们给一个类似于背包问题的动态规划的写的算法。
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string>
#include<sstream>
using namespace std;
int main() {
int input[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 };
for (int a = 0; a < 11; a++)
{
for (int b = a+1; b < 12; b++)
{
for (int c = b+1; c < 13; c++)
{
for (int d = c+1; d < 14; d++)
{
for (int e = d+1; e < 15; e++)
{
for (int f = e+1; f < 16; f++)
{
for (int g = f+1; g < 17; g++)
{
for (int h = g+1; h < 18; h++)
{
for (int i = h+1; i < 19; i++)
{
for (int j = i+1; j < 20; j++)
{
if (input[a]+input[b]+input[c]+input[d]+input[e]+input[f]+input[g]+input[h]+input[i]+input[j] == 80)
{
int sum =input[a]+input[b]+input[c]+input[d]+input[e]+input[f]+input[g]+input[h]+input[i]+input[j];
cout<<input[a]<<"+"<<input[b]<<"+"<<input[c]<<"+"<<input[d]<<"+"<<input[e]<<"+"<<input[f]<<"+"<<input[g]<<"+"<<input[h]<<"+"<<input[i]<<"+"<<input[j]<<"="<<sum<<endl;
cout<<"___________________________________"<<endl;
}
}
}
}
}
}
}
}
}
}
}
}