随笔分类 - DP——杂类
摘要:题目链接:http://codeforces.com/problemset/problem/264/B代码:#include#include#include#includeusing namespace std;const int maxn = 105000;int dp[maxn];vector dx[maxn];void get_div() //筛因子{ for(int i=2; i>n) { memset(dp,0,sizeof(dp)); for(int i=1; i>a; int Max = 1; ...
阅读全文
摘要:题目链接:http://codeforces.com/contest/358/problem/D#include#include#include#includeusing namespace std;const int maxn = 3005;int a[maxn],b[maxn],c[maxn];int dp1[maxn],dp2[maxn];int n;int main(){ //freopen("E:\\acm\\input.txt","r",stdin); cin>>n; for(int i=1; i>a[i]; for(int
阅读全文
摘要:题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=970第一次正式用hash表。代码:#include#include#include#includeusing namespace std;const int maxn = 25500;const int HASH = 1000003;char s[maxn][20];int head[HASH],next[maxn];int dp[maxn];int n;char tem
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4433题目大意:给你一连串密码,(密码是0-》9循环转动),求最少的步骤到达目标数码。算法思路:这个题一看就觉得要用dp思想,就是方程不好想,抓住题目给的可以连续拨动1-3密码,我的dp[i][j][k]表示第i个数字为j,第i+1个数字为k,i及以后到达目标所有的最少步骤。然后记忆化搜。代码:#include#include#include#includeusing namespace std;int dp[1050][10][10];char in[1050],out[1050];int len
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1051题目大意:给你一个字符串,只包含大写字母和‘?’,如果字符串中出现了连续三个以上的元音字母或者连续五个以上的辅音字母,则这个字符串是bad,不然就是good.‘?’号可以替换任意字母。替换以后如果既可以出现连续三个以上的元音字母或者连续五个以上的辅音字母,也可以不出现,则输出Mixed.算法思路(参考别人的):这个地方出现不含‘?’的连续三个以上的元音字母或者连续五个以上的辅音字母则为BAD, 如果含‘?’,则看替换后的情况。具体看代码。代码:#include#include.
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1036#include #include #include #include #include #include #include using namespace std;const int maxn = 505;int m,n;int dp[maxn][maxn][2];int leftsum[maxn][maxn],upsum[maxn][maxn];int main(){ //freopen("E:\\acm\\input.txt","r"
阅读全文
摘要:题目链接:http://poj.org/problem?id=2096#include#include#include#includeusing namespace std;const int maxn = 1005;const int INF = 0x3f3f3f3f;double dp[maxn][maxn];int main(){ int n,s; cin>>n>>s; for(int i=n;i>=0;i--) for(int j=s;j>=0;j--) if(i == n && j == s) dp[n][s] = 0,dp[n+1
阅读全文
摘要:题目链接:http://poj.org/problem?id=1080#include#include#include#includeusing namespace std;const int maxn = 105;const int INF = 0x3f3f3f;int dp[maxn][maxn];int A[maxn],B[maxn];int mymap[6][6] = { {0, 0, 0, 0, 0, 0}, {0,5,-1,-2,-1,-3 }, {0,-1,5,-3,-2,-4 ...
阅读全文
摘要:题目链接:http://poj.org/problem?id=2479#include#include#include#includeusing namespace std;const int maxn = 50005;const int INF = 0x3f3f3f3f;int dp1[maxn];int dp2[maxn];int a[maxn];int N;int main(){ int T; cin>>T; while(T--){ scanf("%d",&N); for(int i=1;i=1;i--){ dp2[i]...
阅读全文
摘要:题目链接:http://poj.org/problem?id=1050#include#include#include#includeusing namespace std;const int maxn = 105;const int INF = 0x3f3f3f;int dp[maxn];int sum[maxn][maxn];int ans;int main(){ //freopen("E:\\acm\\input.txt","r",stdin); int N; cin>>N; for(int i=0;i<=N;i++) sum[0
阅读全文
摘要:题目链接:http://poj.org/problem?id=2127 #include#include#include#includeusing namespace std;const int maxn = 510;int dp[maxn][maxn];int a[maxn],b[maxn];pair > Max[maxn];pair pre[maxn][maxn];void print(int x,int y){ if(x>0 && y>0 && dp[x][y] > 0){ print(pre[x][y].first,pre[x][
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 26;const int INF = 0x3f3f3f;int dp[maxn][maxn][maxn][maxn]; //dp[l1][r1][l2][r2] 表示先手与后手取得到的最大差值。bool vis[maxn][maxn][maxn][..
阅读全文
摘要:题目链接:http://poj.org/problem?id=1631#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 40050;const int INF = 0x3f3f3f;int main(){ //freopen("E:\\acm\\input.txt","r",stdin); int T; cin>>T; while(T--){ int
阅读全文
摘要:题目链接:http://poj.org/problem?id=1609#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 105;const int INF = 0x3f3f3f;int main(){ //freopen("E:\\acm\\input.txt","r",stdin); int N; int dp[maxn][maxn]; int B[maxn]
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705#pragma comment(linker, "/STACK:16777216")#include #include #include #include #include #include #include using namespace std;const int maxn = 110010;long long dp[maxn];vector G[maxn];long long num[maxn];long long N;long long ans;void dfs(i
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1013#include #include #include #include #include #include #include using namespace std;const int maxn = 35;const int INF = 0x3f3f3f;int main(){ //freopen("E:\\acm\\input.txt","r",stdin); int T; cin>>T; for(int t=1;t dp1
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1004#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 105;const int INF = 0x3f3f3f;int num[maxn*2][maxn];int dp[maxn*2][maxn];int main(){ // freopen("E:\\acm\\input.tx
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4681#include#include#include#include#include#include#includeusing namespace std;const int maxn = 1010;const int INF = 0x3f3f3f;char a[maxn],b[maxn],c[maxn];int dp1[maxn][maxn];int dp2[maxn][maxn];void Lcs1(char* s1,char* s2,int m,int n){ for(int i=1;...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4604这个题解有点问题,暂时没时间改,还是参考别人的吧#include #include #include #include #include #include #include #define maxn 100500using namespace std;const int INF = 0x3f3f3f;int a[maxn];int s1[maxn],s2[maxn];int ans;int n;int search_lower_bound(int l,int h,int m){ if(l...
阅读全文
摘要:题目链接:http://poj.org/problem?id=3903 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #define maxn 100005 9 using namespace std;10 11 int stack[maxn];12 int a[maxn];13 int n;14 15 int search_lower_bound(int l,int h,int m){16 if(l == h) return h;17 int mid ...
阅读全文