[dp][uestc oj]J - 男神的约会
2015-05-23 02:02
375 查看
J - 男神的约会
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)Submit Status
有一天男神约了学姐姐去看电影,电影院有一个活动,给你一个10*10的矩阵,每一个格子上都有一个0-9的整数,表示一共十种优惠券中的一种。
观众从左上角的格子开始走,走到右下角。每走到一个有着a号优惠券的格子,都必须要玩一个a分钟的游戏来领取这张优惠券。
每次只能向右或向下走。当走到右下角的时候,如果集齐10种优惠券就可以半价看电影呢。
为了能在学姐姐面前展示自己的才智,男神准备用最少的时间领取全部的优惠券(他要省出最多的时间陪学姐姐)。聪明的你能告诉男神,他最少要花费的时间是多少?
Input
输入包含10行,每行10个数字,以空格隔开,表示格子上的优惠券的种类。数据保证存在合法路径。Output
输出男神走到右下角的最小时间花费。Sample input and output
Sample Input | Sample Output |
---|---|
0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 0 2 1 1 1 1 1 1 1 1 0 3 1 1 1 1 1 1 1 1 0 4 1 1 1 1 1 1 1 1 0 5 1 1 1 1 1 1 1 1 0 6 1 1 1 1 1 1 1 1 0 7 1 1 1 1 1 1 1 1 0 8 1 1 1 1 1 1 1 1 0 9 1 1 1 1 1 1 1 1 5 | 50 |
memset是按字节赋值的,so。int只有赋值-1和0才会对应-1和0
#include<cstdio> #include<memory.h> #include<queue> #include<algorithm> using namespace std; const int MAXSTA=0x3ff; const int MAXij=11; //const int SIGN=16843009;//0x01010101 int dp[MAXij][MAXij][MAXSTA]; int mp[MAXij][MAXij]; bool vis[MAXij][MAXij][MAXSTA]; int solve() { queue<int>qi; queue<int>qj; queue<int>qst; int ci=0,cj=0,cst=1<<mp[0][0]; memset(dp,1,sizeof(dp)); //memset(vis,0,sizeof(vis)); dp[ci][cj][cst]=mp[0][0]; int ni,nj,nst; do { if(ci<9){ ni=ci+1,nj=cj; nst=cst|(1<<mp[ni][nj]); dp[ni][nj][nst]=min(dp[ni][nj][nst],dp[ci][cj][cst]+mp[ni][nj]); if(!vis[ni][nj][nst]) { qi.push(ni); qj.push(nj); qst.push(nst); vis[ni][nj][nst]=true; } } if(cj<9){ ni=ci,nj=cj+1; nst=cst|(1<<mp[ni][nj]); dp[ni][nj][nst]=min(dp[ni][nj][nst],dp[ci][cj][cst]+mp[ni][nj]); if(!vis[ni][nj][nst]) { qi.push(ni); qj.push(nj); qst.push(nst); vis[ni][nj][nst]=true; } } ci=qi.front(); cj=qj.front(); cst=qst.front(); qi.pop(); qj.pop(); qst.pop(); }while(qi.size()); } int main() { //freopen("Jinput.txt","r",stdin); int i,j; for(i=0;i<10;i++) for(j=0;j<10;j++) scanf("%d",&mp[i][j]); solve(); printf("%d",dp[9][9][MAXSTA]); }
相关文章推荐
- 2015 UESTC Training for Dynamic Programming 男神的约会 BFS+状压DP
- UESTC 2015dp专题 j 男神的约会 bfs
- 2015 UESTC Training for Dynamic Programming 男神的礼物(区间dp)
- [dp][uestc oj][最长上升子序列] LIS N - 导弹拦截
- UESTC 2015dp专题 A 男神的礼物 区间dp
- 2015 UESTC Training for Dynamic Programming A- 男神的礼物(区间dp)
- UESTC 1131 男神的礼物 dp:最优矩阵链乘&&triangulation&&双dp
- UESTC_男神的约会 2015 UESTC Training for Dynamic Programming<Problem J>
- uestc1134男神的约会【状压dp】
- 2015 UESTC Training for Dynamic Programming J - 男神的约会(bfs)
- CDOJ 1134 男神的约会 状压dp
- [动态规划] uestc oj A - 男神的礼物
- [dp]uestc oj E - 菲波拉契数制
- [dp]uestc oj 邱老师看电影
- [dp uestc oj] G - 邱老师玩游戏
- cdoj 1134 男神的约会 状压dp
- 哈理工OJ 1864 猥琐宅男——koko(dp)
- USEST OJ 1307 - windy数 数位DP
- UESTC-2016dp专题 F 柱爷与三叉戟不得不说的故事
- UESTC 885 方老师买表 --状压DP