hihocoder 1290 DP】的更多相关文章

http://hihocoder.com/problemset/problem/1290 这题是这次微软笔试的第三题,过的人比第一题少一点,这题一眼看过去就是动态规划,不过转移方程貌似不是很简单,调试了比较久才正确,不过好在是1A,但是最后只留了一个小时多一点给B题,也导致了B题最后也没能AC掉.首先状态是很好确定的p[i][j][k]表示走到第i行第j个格子时,方向是k的情况下的最小改变格子数目.(k from {0, 1})而且由于只有往下和往右走,所以中间过程进行转移时改变的格子不会影响后…
传送门 #1290 : Demo Day 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You work as an intern at a robotics startup. Today is your company's demo day. During the demo your company's robot will be put in a maze and without any information about the maze, it shoul…
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1290 题目大意: 给定k个数,每次可以生成0-N-1中的任何一个数,k个数中出现不同的整数的个数的数学期望 #include <cstdio> #include <cstring> using namespace std; #define N 1005 double dp[N]; int main() { int T,k,n; scanf("%d",&…
#1290 : Demo Day 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You work as an intern at a robotics startup. Today is your company's demo day. During the demo your company's robot will be put in a maze and without any information about the maze, it should be…
题意: 给出n*m的矩阵求最大子矩阵和,要求必须把矩阵中的某一个元素替换成p 代码: //求最大子矩阵和,容易想到压缩之后dp但是这道题要求必须替换一次p,必然优先替换最小的. //这样如果求得的结果恰好等于这个矩阵所有的元素的 //和但不是整个矩阵,并且没有替换元素结果就不对了,需要特判一下这种情况.比如以下两组数据: //2 2 -4 2 2 -4 //1 -1 1 1 //1 1 1 1 dp求出来的结果分别是2和4并且没有替换p. #include<iostream> #include…
1000.a+b. #include<bits/stdc++.h> using namespace std; int a,b; int main() { ios::sync_with_stdio(false); while(~scanf("%d%d",&a,&b)) printf("%d\n",a+b); ; } 1001.不知道n和m大小,可以用一维数组处理位置,或者直接使用vector. #include<bits/stdc++…
http://hihocoder.com/problemset/problem/1043 动态转移方程 :for v=cost..V f[v]=max(f[v],f[v-c[i]]+w[i]); #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int n,m; ]={}; v…
题目链接: http://hihocoder.com/problemset/problem/1300 题解: 先用栈预处理出每个‘)’匹配的‘(’的位子,放在pos数组中. dp[i]表示以i结尾的合法子串个数,则易知转移方程: dp[i]=dp[pos[i]-1]+1: 代码: #include<iostream> #include<cstdio> #include<stack> using namespace std; typedef long long LL; ;…
题目链接: http://hihocoder.com/problemset/problem/1301?sid=804672 题解: 二分答案,每次判断用数位dp做. #include<iostream> #include<cstring> #include<cstdio> using namespace std; typedef long long LL; const LL INFLL = 0x3f3f3f3f3f3f3f3fLL; //dp[x][0]表示高位还没有出…
#1033 : 交错和 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 给定一个数 x,设它十进制展从高位到低位上的数位依次是 a0, a1, ..., an - 1,定义交错和函数: f(x) = a0 - a1 + a2 - ... + ( - 1)n - 1an - 1 比如: f(3214567) = 3 - 2 + 1 - 4 + 5 - 6 + 7 = 4 给定 输入 输入数据仅一行包括三个整数.l, r, k(0 ≤ l ≤ r ≤ 1018, |…