I have understood all my questions for a long time. After a long time, I am so sleepy. I have no time to write Analysis in the middle of the night. I have to go to bed and let myself think about it. I will write it tomorrow. There are some cities, each row is a flight from the first city to another city. The cost is zero.
#include
#include
#include
#include#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long#define eps 1e-7#define inf 0xfffffffconst ll INF = 1ll<<61;using namespace std;//vector
> G;//typedef pair
P;//vector
> ::iterator iter;////map
mp;//map
::iterator p;//int n,k;int dp[10 + 5][1000 + 5];int travel[10 + 5][1000 + 5];int cost[10 + 5][10 + 5][1000 + 5];void clear() {memset(dp,-1,sizeof(dp));memset(travel,0,sizeof(travel));memset(cost,0,sizeof(cost));}int main() {int Case = 0;while(scanf(%d %d,&n,&k),n + k) {clear();for(int i=1;i<=n;i++) {for(int j=1;j<=n;j++) {if(i != j) {scanf(%d,&travel[i][j]);for(int l=0;l
dp[l][j - 1] + cost[l][i][tmp])minn = dp[l][j - 1] + cost[l][i][tmp];}dp[i][j] = minn;}}printf(Scenario #%d,++Case);if(dp[n][k] < 0)printf(No flight possible.); elseprintf(The best flight costs %d.,dp[n][k]); }return EXIT_SUCCESS;}