[Usaco2015 OPEN] Palindromic Paths】的更多相关文章

DP.. f[i][j][k]表示左上结束节点是第i条副对角线上的第j个点,右下结束节点是第n*2-i条副对角线上的第k个点,构成回文的方案数. i那维滚动一下.时间复杂度O(n^3)空间复杂度O(n^2) #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #define ui unsigned int using n…
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4098 [算法] 显然 , 回文路径中第i个字母的位置(x , y)必然满足 : x + y - 1 = i 用f[i][j][k]表示现在在第i步 , 左上的横坐标为j , 右下的横坐标为k , 有多少种方案使得两边路径上的字母序列相同 , DP即可 时间复杂度 : O(N ^ 3) 滚动数组 , 将空间复杂度优化为O(N ^ 2) [代码] #include<bits/stdc+…
[USACO15OPEN]回文的路径Palindromic Paths 题目描述 Farmer John's farm is in the shape of an N \times NN×N grid of fields (1 \le N \le 5001≤N≤500), each labeled with a letter in the alphabet. For example: ABCD BXZX CDXB WCBA Each day, Bessie the cow walks from…
5020: Palindromic Paths  Time Limit(Common/Java):10000MS/30000MS     Memory Limit:65536KByteTotal Submit: 8            Accepted:4 Description Given an N×N grid of fields (1≤N≤500), each labeled with a letter in the alphabet. For example: ABCD BXZXCDX…
P3126 [USACO15OPEN]回文的路径Palindromic Paths 看到这题题解不多,蒟蒻便想更加通俗易懂地分享一点自己的心得,欢迎大佬批评指正^_^ 像这种棋盘形的两边同时做的dp还有 P1006 传纸条, P1004 方格取数, T35377 大教室中传纸条 一.思路改进 对于这种题目最暴力的方法无非是分别枚举左上角和右下角两点坐标 (f[ i ][ j ][ k ][ l ] = f[ i-1 ][ j ][ k+1 ][ l ] + f[ i-1 ][ j ][ k ][…
题目链接:Palindromic Paths 题意: 给你一个n行m列的矩阵,这个矩阵被0或者1所填充,你需要从点(1,1)走到点(n,m).这个时候会有很多路径,每一条路径对应一个01串,你可以改变这个矩阵中某些位置的值,你需要保证改变之后每一条路径串都是回文串. 最后输出你最少需要改变多少位置 题解: 因为你要保证每一条路径都是回文路径,那么如下面这组样例: 3 5 1 0 1 0 0 1 1 1 1 0 0 0 1 0 0 起点位置(1,1)的值是1但是终点位置(n,m)的值是0,但是在一…
题目描述 农夫FJ的农场是一个N*N的正方形矩阵(2\le N\le 5002≤N≤500),每一块用一个字母作标记.比如说: ABCD BXZX CDXB WCBA 某一天,FJ从农场的左上角走到右下角,当然啦,每次他只能往右或者往下走一格.FJ把他走过的路径记录下来.现在,请你把他统计一下,所有路径中,回文串的数量(从前往后读和从后往前读一模一样的字符串称为回文串). 输入输出格式 输入格式: 第一行包括一个整数N,表示农场的大小,接下来输入一个N*N的字母矩阵. 输出格式: Please…
描述 Given an N×N grid of fields (1≤N≤500), each labeled with a letter in the alphabet. For example: ABCD BXZXCDXBWCBA Each day, Susa walks from the upper-left field to the lower-right field, each step taking her either one field to the right or one fi…
题目链接 http://codeforces.com/contest/1205/problem/C 题解 菜鸡永远做着变巨的梦 然而依然连div1BC题都不会做 要是那天去打cf怕是又要1题滚粗了.... 首先第一步显然是对于所有\(i+j\)为偶数的点(下称"偶点")求出\(a_{i,j}\)的值,对于所有\(i+j\)为奇数的点(下称"奇点")求出它们之间的相对关系.也就相当于强行令\(a_{1,2}=x\)之后求出所有奇点是\(x\)还是\(x\ \text{…
题目链接 问题分析 首先可以想到,坐标和为奇数的位置可以被唯一确定.同样的,如果假定\((1,2)\)是\(0\),那么坐标和为偶数的位置也可以被唯一确定.这样总共使用了\(n^2-3\)次询问. 那么接下来就需要在\(3\)步之内判断是否要翻转坐标和为偶数的位置. 如果仅仅只是这样简单的判断: printf( "? 1 1 2 3\n" ); fflush( stdout ); int x; scanf( "%d", &x ); if( x == 1 &a…
目录 @description@ @solution@ @accepted code@ @details@ @description@ 这是一道交互题. 现在有一个 n*n 的矩阵,每个位置是 0 或 1.现在已知 n 为奇数.左上角为 1.右下角为 0. 你可以向交互库给出询问 "? x1 y1 x2 y2",交互库会回答是否存在一条路径从 (x1, y1) 出发仅往右或往下走到达 (x2, y2),且路径上所有数拼起来形成回文串.如果存在为 1,否则为 0. 请注意询问时必须保证…
题目链接:https://codeforces.com/contest/1366/problem/C 题意 有一个 $n \times m$ 的 $01$迷宫,要使从 $(1,1)$ 到 $(n,m)$ 的所有路径均为回文串,至少要变换多少字符. 题解一 用 $bfs$ 得到回文串每个位置可能的 $01$ 个数,对称位置变换 $01$ 总个数中的较少值即可. 代码 #include <bits/stdc++.h> using namespace std; const int dir[4][2]…
题意:有一个\(n\)x\(m\)的矩阵,从\((1,1)\)出发走到\((n,m)\),问最少修改多少个数,使得所有路径上的数对应相等(e.g:\((1,2)\)和\((n-1,m)\)或\((2,1)\)和\((n,m-1)\)). 题解:我们将二维的点的坐标转化为一维的步数(到\((1,1)\)的路径),统计所有步数相同的数字,然后枚举步数及相对应位置的数字,这些位置上的所有数字都应该相等,所以取一个\(0\)和\(1\)出现次数的最小值即可. 代码: #include <iostream…
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem 10983 18765 Y 1036 [ZJOI2008]树的统计Count 5293 13132 Y 1588 [HNOI2002]营业额统计 5056 13607 1001 [BeiJing2006]狼抓兔子 4526 18386 Y 2002 [Hnoi2010]Bounce 弹飞绵羊 43…
You are given a tree (a connected acyclic undirected graph) of n vertices. Vertices are numbered from 1 to n and each vertex is assigned a character from a to t. A path in the tree is said to be palindromic if at least one permutation of the labels i…
Codeforces Round #580 (Div. 1) https://codeforces.com/contest/1205 A. Almost Equal 随便构造一下吧...太水了不说了,放个代码吧. #include<bits/stdc++.h> using namespace std; void read(int &x) { x=0;int f=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-'…
4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 113[Submit][Status][Discuss] Description Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), c…
简单的拓扑图dp.. A(i, j), B(i, j) 表示从点 i 长度为 j 的两种路径是否存在. 用bitset就行了 时间复杂度O(m) ---------------------------------------------------------------- #include<bits/stdc++.h>   #define clr(x, c) memset(x, c, sizeof(x)) #define rep(i, n) for(int i = 0; i < n;…
[Usaco2015 Jan]Grass Cownoisseur 题目 给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过? (一个点在路径中无论出现多少正整数次对答案的贡献均为1) INPUT The first line of input contains N and M, giving the number of fields and the number of one-way paths (1 <= N, M <= 100,…
BZOJ3887 [Usaco2015 Jan] Grass Cownoisseur Description In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each…
[Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 353  Solved: 236[Submit][Status][Discuss] Description Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), conveni…
题意: 给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过?(一个点在路径中无论出现多少正整数次对答案的贡献均为1) =>有向图我们先考虑缩点.然后观察缩点后的图可以发现新的路径中必定只有一条边是反向的才符合条件.那么我们可以联想到某道最短路的题将边反向存一遍后分别从s和t跑一跑.那么这里bfs跑一跑就行了.然后有一个坑点:这种重建图的注意es和edges不然es会在中途就被修改掉了... #include<cstdio> #…
BZOJ4390: [Usaco2015 dec]Max Flow Description Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), conveniently numbered 1…N. Each pipe connects a pair of stalls, and all stalls are conn…
BZOJ_3887_[Usaco2015 Jan]Grass Cownoisseur_强连通分量+拓扑排序+DP Description In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1…
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 即给定一个字符串,求它的最长回文子串的长度(或者最长回文子串). 解法一 对于一个问题,一定可以找到一个傻的可爱的暴力解法,本题的暴力解法即…
题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 给一个字符串…
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5", "1->3"] 这道题给我们一个二叉树,让我们返回所有根到叶节点的路径,跟之前那道Path Sum II 二叉树路径之和之二很类似,比那道稍微简单一…
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obstacle in the middl…
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in t…
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 这道题让我们求最长回文子串,首先说下什么是回文串,就是正读反读都一样的字符串,比如 "bob", "level", &q…