#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;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)