求助!!!文件输入输出
  • 板块题目总版
  • 楼主Bigfish_
  • 当前回复1
  • 已保存回复1
  • 发布时间2020/11/6 23:31
  • 上次更新2023/11/5 08:42:27
查看原帖
求助!!!文件输入输出
343245
Bigfish_楼主2020/11/6 23:31

如题,用的是freopen为什么输出文件是0? 单独运行都没有错??

#include <bits/stdc++.h>
using namespace std;
unsigned long f[10000]={0};
unsigned long w[10000];
unsigned long c[10000];
int main()
{
	/*freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);*/
	unsigned long n,m;
	cin>>m>>n;
	for(int t=1;t<=n;++t)
		cin>>w[t]>>c[t];	
	for(int t=1;t<=n;++t)
		for(int i=w[t];i<=m;++i)
			if(f[i-w[t]]+c[t]>=f[i]) 
				f[i]=f[i-w[t]]+c[t];
	cout<<f[m];return 0;
}

把fclose删了,直接cout可以

2020/11/6 23:31
加载中...