ZOJ 3605Find the Marble
来源:互联网 发布:cms监控软件使用说明 编辑:程序博客网 时间:2024/06/05 04:28
传说中的江湖赌骗术,能自己想到的dp都不是什么复杂的dp。用dp[i][j]k]表示前i次交换看漏j次最后猜k的可能排列数,递推时,若第i步看漏,则dp[i][j][k] += dp[i-1][j-1][k]。若第i步没看漏,则分两种情况:第i步的交换与k有关,另外一个是l,则dp[i][j][k] += dp[i-1][j][l];若无关,则dp[i][j][k] += dp[i-1][j][k]。最后在dp[m][m-k]中找最大值输出下标即可。
但是数组要用long long或者double,另外有可能m=k=0,所以初值应是dp[0][0][s] = 1。
#include <stdio.h>#include <memory.h>int n, m, k, s;long long dp[51][51][51];int from[51], to[51];inline int leadto(int s, int i){if(s == from[i]) return to[i];if(s == to[i]) return from[i];else return 0;}int main(){int N, i, j, temp, maxi;long long max, *a;scanf("%d", &N);while(N --){scanf("%d%d%d%d", &n, &m, &k, &s);for(i=1; i<=m; ++i)scanf("%d%d", &from[i], &to[i]);memset(dp, 0, sizeof(dp));dp[0][0][s] = 1;for(i=1; i<=m; ++i){for(j=1; j<=n; ++j){temp = leadto(j, i);for(s=0; s<=i; ++s){if(s != 0)dp[i][s][j] += dp[i-1][s-1][j];if(temp != 0)dp[i][s][j] += dp[i-1][s][temp];elsedp[i][s][j] += dp[i-1][s][j];}}}max = -1, a = dp[m][m-k];for(i=1; i<=n; ++i){if(a[i] > max){max = a[i];maxi = i;}}printf("%d\n", maxi);}return 0;}
- ZOJ 3605Find the Marble
- ZOJ 3605 Find the Marble
- ZOJ 3605Find the Marble
- ZOJ 3605 Find the Marble
- Find the Marble ZOJ
- ZOJ 3605 Find the Marble(三维dp)
- ZOJ 3605 Find the Marble(DP)
- zoj 3605 Find the Marble 计数dp
- zoj 3605 Find the Marble (概率dp)
- 【DP】ZOJ 3605 Find the Marble
- ZOJ 3605 Find the Marble(dp)
- ZOJ 3605-F - Find the Marble-DP
- zoj 3605 Find the Marble (dp)
- ZOJ 3605 Find the Marble(dp啊 三维)
- ZOJ3605-Find the Marble
- ZOJ3605-Find the Marble(概率DP)
- zoj3605 Find the Marble --- 概率dp
- ZOj3605--- Find the Marble(概率dp)
- Drop-down list in OA Framework
- POJ3432《Count Squares》方法:哈希
- 2013第六周上机任务【项目2 程序填空(1)】
- 《剑指Offer》读书笔记---面试题14:调整数组顺序使奇数位于偶数前面
- Ant上传文件到远程服务器
- ZOJ 3605Find the Marble
- 将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
- MOQL--操作数(Operand) (二)
- 重要网址收藏
- opencv 智能指针 Ptr
- 第六周项目二——指针填空A
- 第六周项目二。
- 动态获取手机中view的宽高度
- 单片机沉思录——static