zoj 1524 Supermarket

zoj 1524 Supermarket,第1张

zoj 1524 Supermarket
#include<stdio.h>#include<limits.h>int main(){int m, n, a[101];double dp[101];while (scanf("%d %d", &m, &n), m || n){int i, j, k;double p;for (i = 1; i <= m; i++){scanf("%d", &a[i]);dp[i] = INT_MAX;}dp[0] = 0;for (j = 1; j <= n; j++){scanf("%d %lf", &k, &p);for (i = m; i > 0; i--)if (a[i] == k && dp[i - 1] != INT_MAX && dp[i - 1] + p < dp[i])dp[i] = dp[i - 1] + p;}if (dp[m] != INT_MAX)printf("%.2lfn", dp[m]);elseputs("Impossible");}return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4909250.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存