Language: C++

//Solution for aoj:0530 Pyon-Pyon River Crossing
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int INF = 100000000, MAX_N = 150;
typedef pair<int, int> P;
int n, m, ans;
int dp[MAX_N + 20][10010][760];
P stone, stone2;
vector<P> Stone[151]; //first:??????second:???????????????
int main(){
	while (cin >> n >> m){
		if (!n&&!m)
			return 0;
		for (int i = 1; i <= n; i++)
			Stone[i].clear();
		for (int i = 1; i <= n; i++){
			int a, b, c;
			cin >> c;
			for (int j = 0; j < c; j++){
				cin >> a >> b;
				Stone[i].push_back(P(a, b));
			}
		}
		for (int i = 2; i <= n; i++){
			for (int j = 1; j <= 1000; j++){
				for (int k = 0; k <= m; k++){
					dp[i][j][k] = 0;
				}
			}
		}
		for (int i = 0; i < Stone[2].size(); i++){
			stone = Stone[2][i];
			dp[2][stone.first][m] = INF;
		}
		for (int i = 3; i <= n; i++){
			for (int j = 0; j < Stone[i].size(); j++){
				stone = Stone[i][j];
				for (int k = 0; k <= m; k++)
					dp[i][stone.first][k] = INF;
			}
		}
		for (int i = 1; i < n; i++){
			for (int j = 0; j < Stone[i].size(); j++){
				stone = Stone[i][j];
				for (int k = 0; k < Stone[i + 1].size(); k++){
					stone2 = Stone[i + 1][k];
					for (int l = m; l >= m - (i + 1) / 2; l--){
						if (l < 0)
							break;
						if (l != m)
							dp[i + 1][stone2.first][l] = min(dp[i + 1][stone2.first][l], dp[i + 1][stone2.first][l + 1]);
						dp[i + 1][stone2.first][l] = min(dp[i + 1][stone2.first][l], (stone.second + stone2.second)*abs(stone.first - stone2.first) + dp[i][stone.first][l]);
					}
				}
				for (int k = 0; k < Stone[i + 2].size(); k++){
					stone2 = Stone[i + 2][k];
					for (int l = m - 1; l >= m - (i + 2) / 2; l--){
						if (l < 0)
							break;
						if (l != m)
							dp[i + 1][stone2.first][l] = min(dp[i + 2][stone2.first][l], dp[i + 2][stone2.first][l + 1]);
						dp[i + 2][stone2.first][l] = min(dp[i + 2][stone2.first][l], (stone.second + stone2.second)*abs(stone.first - stone2.first) + dp[i][stone.first][l + 1]);
					}
				}
			}
		}
		ans = INF;
		for (int i = 0; i < Stone[n].size(); i++){
			stone = Stone[n][i];
			ans = min(dp[n][stone.first][0], ans);
		}
		for (int i = 0; i < Stone[n - 1].size(); i++){
			if (m == 0)
				break;
			stone = Stone[n - 1][i];
			if (dp[n - 1][stone.first][1])
				ans = min(dp[n - 1][stone.first][1], ans);
		}
		cout << ans << endl;
	}
}

Compiler output:
/tmp/cc6d0wBG.o: in function `main':
a.cc:(.text+0x4b): relocation truncated to fit: R_X86_64_PC32 against symbol `Stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0xd2): relocation truncated to fit: R_X86_64_PC32 against symbol `Stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0x1b4): relocation truncated to fit: R_X86_64_PC32 against symbol `Stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0x1c6): relocation truncated to fit: R_X86_64_PC32 against symbol `stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0x1d4): relocation truncated to fit: R_X86_64_PC32 against symbol `stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0x216): relocation truncated to fit: R_X86_64_PC32 against symbol `Stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0x25e): relocation truncated to fit: R_X86_64_PC32 against symbol `Stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0x27b): relocation truncated to fit: R_X86_64_PC32 against symbol `stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0x292): relocation truncated to fit: R_X86_64_PC32 against symbol `stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0x2fd): relocation truncated to fit: R_X86_64_PC32 against symbol `Stone' defined in .bss section in /tmp/cc6d0wBG.o
a.cc:(.text+0x35b): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status