C++编程,高手进

2025-02-24 11:45:14
推荐回答(3个)
回答1:

#include
#include
#include using namespace std;int main()
{
//f:array[0..100,-2000..2000] of boolean;
bool f[100][4000] = {false};
long n,start,max,i,j,jj;
long a[100]; // 读入数据 ///////////////////////////////////////////////////////////////////// std::ifstream song_in("song.in"); // 测试文件是否存在
if(!song_in)
cout << "Wrong to open song.in file!\n";
else
{
song_in>>n;
song_in>>start;
song_in>>max; cout< } for (i = 1; i <= n-1; i++)
{
song_in>>a[i+1];
cout< } // 开始计算 ///////////////////////////////////////////////////////////////////// f[1][start + 2000] = true; for (i = 2; i <= n; i++)
for (j = 0; j <= max; j++)
{
if (j - a[i] >= 0)
{
f[i][j + 2000] = f[i-1][j-a[i] + 2000];
}
if (j + a[i] <= max)
{
f[i][j + 2000] = f[i][j + 2000] || f[i-1][j+a[i] + 2000];
} }

jj = -1; for (j = max; j >= 0; j--)
if (f[n][j + 2000])
{
jj = j;
break;
} song_in.close(); // 输出结果 /////////////////////////////////////////////////////////////////////
std::ofstream song_out("song.out");
song_out.open("song.out");
song_out<<"jj"< song_out.close(); cout<<"最后结果:"<}

回答2:

不是太明白,你是想要一个能读这样文件的源代码?

回答3:

能说的详细点吗?