为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > 资源分配问题

资源分配问题

2017-10-13 3页 doc 13KB 30阅读

用户头像

is_731942

暂无简介

举报
资源分配问题资源分配问题 // 资源分配问题 《算法设计与分析》P160 #include using namespace std; int a[100][100]; double f[100]; int main() { int i, j, k, m, n, rest, gain[100]; double q[100], temp[100]; cout > m; cout > n; cout > q[j]; f[j] = q[j]; } for(j = 1; j > q[j]; a[k][j] = 0; ...
资源分配问题
资源分配问题 // 资源分配问题 《算法设计与分析》P160 #include using namespace std; int a[100][100]; double f[100]; int main() { int i, j, k, m, n, rest, gain[100]; double q[100], temp[100]; cout << "How many item? "; cin >> m; cout << "How many money? "; cin >> n; cout << "input one item gain table:"; for(j = 1; j <= n; ++j) { cin >> q[j]; f[j] = q[j]; } for(j = 1; j <= n; ++j) a[1][j] = j; for(k = 2; k <= m; ++k) { cout << "input another item gain table:"; for(j = 1; j <= n; ++j) { temp[j] = q[j]; cin >> q[j]; a[k][j] = 0; } for(j = 1; j <= n; ++j) { for(i = 1; i < j; ++i) if(f[j-i] + q[i] > temp[j]) { temp[j] = f[j-i] + q[i]; a[k][j] = i; } } for(j = 1; j <= n; ++j) f[j] = temp[j]; } rest = n; for(i = m; i >= 1; --i) { gain[i] = a[i][rest]; rest -= gain[i]; } for(i = 1; i <= m; ++i) cout << "项目" << i << "分配" << gain[i] << "个资源" << endl; cout << "最大利润" << f[n] << endl; return 0; } /* 输入数据 0.11 0.13 0.15 0.21 0.24 0.30 0.35 0.12 0.16 0.21 0.23 0.25 0.24 0.34 0.08 0.12 0.20 0.24 0.26 0.30 0.35 */
/
本文档为【资源分配问题】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索