64pts求调
查看原帖
64pts求调
847559
Chtholly__Nota楼主2024/10/16 01:08

代码是这样的

#include <bits/stdc++.h>
#define int long long
using namespace std;

int f[100005][10];

int c, t, n, len;

string s;

int a[10];

int p[10] = {1, 10, 100, 1000, 10000, 100000, 1000000};

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> c >> t;
	while (t--)
	{
		cin >> s;
		len = s.size();
		memset(f, 1, sizeof(f));
		memset(f[len + 1], 0, sizeof(f[len + 1]));
		s = " " + s;
		for (int i = 1; i <= 9; i++)
			cin >> a[i];
		for (int i = len; i >= 1; i--)
		{
			for (int j = 0; j <= 5; j++)
			{
				f[i][j] = min(f[i + 1][j] + a[s[i] - '0'], f[i + 1][j + 1] + (s[i] - '0') * p[j]);
			}
		}
		cout << f[1][0] << "\n";
	}
	return 0;
}
2024/10/16 01:08
加载中...