|
ID
|
Origin
|
Title
|
||
|---|---|---|---|---|
| 31 / 51 | Problem A | HDU 4175 | Class Schedule | |
| 27 / 140 | Problem B | HDU 4193 | Non-negative Partial Sums | |
| 5 / 17 | Problem C | HDU 4212 | Shut the Box | |
| 3 / 9 | Problem D | HDU 4216 | Computational Geometry? | |
| 2 / 3 | Problem E | HDU 4219 | Randomization? | |
| Problem F | HDU 4234 | Moving Points | ||
| 9 / 17 | Problem G | HDU 4243 | Maximum in the Cycle of 1 | |
| Problem H | HDU 4253 | Two Famous Companies | ||
| 5 / 25 | Problem I | HDU 4254 | A Famous Game | |
| 31 / 141 | Problem J | HDU 4268 | Alice and Bob | |
| 23 / 46 | Problem K | HDU 4260 | The End of The World | |
| 56 / 167 | Problem L | CodeForces 557B | Pasha and Tea |
A
题意:有C类课程,每类课程有T个班,不同的班在不同位置,上不同的班有不同的花费,初始位置是0,末位置L,求最小花费。
比较简单的递推,f[i][j]表示上i类课的j个班所需的最小花费。最后求f[c]中的最小值就可以了。
1 #include <iostream> 2 #include <cstdio> 3 #include <fstream> 4 #include <algorithm> 5 #include <cmath> 6 #include <deque> 7 #include <vector> 8 #include <queue> 9 #include <string> 10 #include <cstring> 11 #include <map> 12 #include <stack> 13 #include <set> 14 #define LL long long 15 #define eps 1e-8 16 #define INF 0x3f3f3f3f 17 //#define OPEN_FILE 18 using namespace std; 19 int T, c, t, L; 20 struct Node{ 21 int pos, v; 22 }p[30][1005]; 23 int f[30][1005]; 24 int main() 25 { 26 #ifdef OPEN_FILE 27 freopen("in.txt", "r", stdin); 28 //freopen("out.txt", "w", stdout); 29 #endif // OPEN_FILE 30 scanf("%d", &T); 31 for (int cas = 1; cas <= T; cas++){ 32 scanf("%d%d%d", &c, &t, &L); 33 for (int i = 1; i <= c; i++){ 34 for (int j = 1; j <= t; j++){ 35 scanf("%d%d", &p[i][j].pos, &p[i][j].v); 36 } 37 } 38 memset(f, INF, sizeof(f)); 39 for (int i = 1; i <= t; i++){ 40 f[1][i] = p[1][i].pos + p[1][i].v; 41 } 42 for (int i = 2; i <= c; i++){ 43 for (int j = 1; j <= t; j++){ 44 for (int k = 1; k <= t; k++){ 45 int dis = abs(p[i - 1][k].pos - p[i][j].pos); 46 f[i][j] = min(f[i][j], f[i - 1][k] + dis + p[i][j].v); 47 } 48 } 49 } 50 int ans = INF; 51 for (int i = 1; i <= t; i++){ 52 int dis = abs(p[c][i].pos - L); 53 ans = min(ans, f[c][i] + dis); 54 } 55 printf("%d\n", ans); 56 } 57 }