EOF 440 Buying Feed (未提交)
囧……在EOJ里怎么找不到提交的地方?求问,哪里有提交这道题的地方?
不过把代码写出来了
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 struct MQ 6 { 7 int pos[101]; 8 long long val[101]; 9 int head, tail, winlen; 10 void reset(const int& _winlen) 11 { 12 head = 0, tail = -1, winlen = _winlen; 13 } 14 void push_back(const int& index, const long long& _val) 15 { 16 while(head <= tail && pos[tail] > _val) 17 tail--; 18 pos[++tail] = index; 19 val[tail] = _val; 20 while(index - pos[head] >= winlen) 21 head++; 22 } 23 long long top() 24 { 25 return val[head]; 26 } 27 }q; 28 struct Store 29 { 30 int x, f, c; 31 }s[101]; 32 bool cmp(const Store& a, const Store& b) 33 { 34 return a.x < b.x; 35 } 36 long long K, E, N, dp[101][101]; 37 38 /*void Print() 39 { 40 for(int i=0 ; i<=N ; i++) 41 { 42 for(int j=0 ; j<=K ; j++) 43 cout << dp[i][j] << " "; 44 cout << endl; 45 } 46 cout << endl; 47 }*/ 48 49 int main() 50 { 51 int t; cin >> t; 52 while(t--) 53 { 54 cin >> K >> E >> N; 55 for(int i=1 ; i<=N ; i++) 56 { 57 cin >> s[i].x >> s[i].f >> s[i].c; 58 } 59 sort(s+1, s+1+N, cmp); 60 for(int j=1 ; j<=K ; j++) 61 dp[0][j] = 0xfffffff; 62 dp[0][0] = 0; 63 for(int i=1 ; i<=N ; i++) 64 { 65 q.reset(s[i].f+1); 66 for(int j=0 ; j<=K ; j++) 67 { 68 dp[i][j] = 0xfffffff; 69 q.push_back(j, dp[i-1][j]+j*j*(s[i].x-s[i-1].x)-j*s[i].c); 70 dp[i][j] = q.top() + j * s[i].c; 71 } 72 } 73 cout << dp[N][K]+K*K*(E-s[N].x) << endl; 74 } 75 }
浙公网安备 33010602011771号