Time of Update: 2018-12-05
描述:要用到Ferrers圖演算法,看了一下似懂非懂,通過別人的代碼,也似乎看懂了#include <cstdio>#include <cstring>long long v[310][310]= {{0}};void dp(){ v[0][0]=1; for(int i=0; i<=300; i++) for(int j=1; j<=300; j++) { if(i>=j) v[i][j]+
Time of Update: 2018-12-05
描述:題目是讓你求這個矩陣中的子矩陣的元素和,把最大的找出來輸出,因為沒有想到其他辦法,就直接暴出來了#include <cstdio>int num[110][110];int main(){ //freopen("a.txt","r",stdin); int n,count,sum; while(scanf("%d",&n)!=EOF) { sum=-10000000; for(int i=0; i<n; i++)
Time of Update: 2018-12-05
描述:if(v[x]!=v[y]) sum[x][y]=dp(x,y-1)+dp(x+1,y)-dp(x+1,y-1);如果不相等,那麼需要計算的就是字串從[x,y]之間的,所以從[x,y-1]與[x+1,y]多計算了[x+1,y-1]這一段,需要減去。 if(str[x]==str[y])
Time of Update: 2018-12-05
描述:計算從點(1,1)到點(n,m)一共有多少條路徑#include <cstdio>#include <cstring>int arr[110][110];int main(){ // freopen("a.txt","r",stdin); int t,n,m,len; scanf("%d",&t); while(t--) { memset(arr,0,sizeof(arr)); scanf("%d
Time of Update: 2018-12-05
描述:暈了,因為讀入字串時用gets讀入的,所以一直錯,可是用scanf讀入卻對了,無語。題意是有一個字串,字串的長度len表示有一個len*len的矩陣,?表示在這一列的人一行可以放一個皇后,皇后只能攻擊一列和周圍把個地方的目標,數字及字母是十六進位,用n表示,表示在這一列的第n行必須有一個皇后,也就是說這一列已經確定了只會有這一個皇后#include <cstdio>#include <cstring>#include <cstdlib>long
Time of Update: 2018-12-05
描述:可惡的奇葩題,不但要求記憶化搜尋,而且還要求高精度,大資料 10^100,真受不了,非得開了個大數才解決的,開小數還逾時#include <cstdio>#include <cstring>#define N 100000000char str[10010],s[110];int v[110][10010][13],len[110][10010];int max(int x,int y){ return x>y?x:y;}int main(){ //
Time of Update: 2018-12-05
描述:博弈題目,雙方可以數組任何一邊取連續的的幾個數組元素的值的和,但不能同時從兩邊去,可以從一邊一次取到頭#include <cstdio>#include <cstring>#include <cstdlib>int n,sum;int arr[110];int v[110][110];int min(int x,int y){ return x>y?y:x;}int dp(int x,int y){ if(v[x][y]>sum)
Time of Update: 2018-12-05
/*題意:給定一個有向網路,邊權為拆掉邊的代價,現在1要到n去,n試圖阻止1到底,它至少花多大代價。 有一個條件,1可以在任意兩點(不含1和n)加入一條邊(此邊不可被拆除),求n要花費的最小代價最大值題解:如果沒有後面一個條件,答案就是最小割。易知加入兩條邊必須從源集到彙集(不然原最小割可以割斷聯絡) 對於求一遍1到n的最大流網路狀態network和最小割tmp,加入一條滿足上述條件的邊,然後再求1到n的最大流,得到的就是附加代價, 只需要使得這個附加代價最大即可。
Time of Update: 2018-12-05
描述:最長子序列,不過需要注意的是小烏龜的重量會依次加在下層的小烏龜身上,所以越往下,小烏龜所承受的重量越大#include <cstdio>#include <cstdlib>#include <cstring>int v[5610][2],arr[5610];int cmp(const void *p1,const void *p2){ int c = ((int *)p1)[1] - ((int *)p2)[1]; if(c!=0)
Time of Update: 2018-12-05
描述:由於數組會到10000,所以普通的記憶化搜尋會逾時,需要改進一下#include <cstdio>int n,sum,len;int v[10010][2],arr[10010],s[10010];int min(int x,int y){ return x>y?y:x;}int max(int x,int y){ return x>y?x:y;}int cal(int p,int &len){ if(!len||s[len]<p)
Time of Update: 2018-12-05
//10250 The Other Two Tree#include <stdio.h>void main(){double x0, y0, x1, y1;double x2, y2, x3, y3;double cx, cy;while((scanf("%lf%lf%lf%lf", &x0, &y0, &x1, &y1)) != EOF){if(x0 == x1 && y0 ==
Time of Update: 2018-12-05
描述:以第一個字串為貪心對象,在其他字串中尋找一個與此字串從字串下標開始匹配最多的字串,如果在匹配過程中存在不相符的,那麼前面這些匹配成功的就不需要再次不輸入,也就是說這些部分在press時就不需要了,只需要press以後不匹配的就可以了,然後在意這個字串為貪心對象,以此類推即可#include <cstdio>#include <cstdlib>#include <cstring>int cmp(const void *p1,const void *p2){
Time of Update: 2018-12-05
描述:找中位元,然後求絕對值的和就是了#include <cstdio>#include <cstdlib>int cmp(const void *p1,const void *p2){ return *(int *)p1 - *(int *)p2;}int num[510];int main(){ //freopen("a.txt","r",stdin); int n,m,count,sum; scanf("%d",&n);
Time of Update: 2018-12-05
描述:博弈題目,第一次看這種題,實在不,明白什麼意思,後來才知道是博弈題目,由於是巴什博弈(Bash Game)。(i=1;i<=n;i++),(j=0;j<=m;j++) i-arr[j]>=0,num[i-arr[j]]==0則代表Stan可以移動石塊,數組num標記為1,(開始時全部初始化為零,num[0]=1,零代表Ollie剛剛在此處移動數組),直到出現num[n]為1時,終止迴圈,此時就可以輸出Stan wins,否則最後就輸出Ollie wins#include
Time of Update: 2018-12-05
描述:計算存在的最長迴文串長度#include <cstdio>#include <cstring>#include <cstdlib>int n,sum;char str[1010];int v[1010][1010];int max(int x,int y){ return x>y?x:y;}int dp(int x,int y){ if(v[x][y]) return v[x][y]; if(x==y) return
Time of Update: 2018-12-05
描述:沒什麼難度,比較水一點的題#include <cstdio>#include <cstring>struct fli{ int d[10]; int flight[10][35]; int sum; int count;};fli f[12];int main(){// freopen("a.txt","r",stdin); int n,m,k,t=0,p; int v[12]; while(scanf("%d%d",&
Time of Update: 2018-12-05
描述:比上一題還要麻煩的題,不過改進了方法,比上一題耗時還要少,先把輸入的數組複製成三分,分別在右,下,右下三個地方,然後計算從0下標到當前下標的和,然後再暴一下就可以了#include<cstdio>int main(){ // freopen("a.txt","r",stdin); int t,n,count,sum; int num[160][160]; scanf("%d",&t); while(t--) {
Time of Update: 2018-12-05
描述:經典dp問題,狀態方程:if(s[x]!=s[y]) min(dp(x,y-1),dp(x+1,y),dp(x+1,y-1));else dp(x+1,y-1);#include <cstdio>#include <cstring>int n;int v[1010][1010];char s[1010];int min(int x,int y){ return x>y?y:x;}int dp(int x,int y){ if(v[x][y]!=-1
Time of Update: 2018-12-05
描述:這道題具體是怎麼回事,我也不清楚,先看看這位大神的題解吧http://hi.baidu.com/knowledgetime/item/1e890017baa663fd87ad4eb5#include <cstdio>#include <cstring>int main(){ // freopen("a.txt","r",stdin); int n,len; char s[10010];
Time of Update: 2018-12-05
描述:剛開始沒看懂題目,原來是要湊出一個數(x,y),使得x^2+y^2==s^2#include <cstdio>#include <cstring>int v[310][310],arr[45][2];int pow_two(int x,int y){ return x*x+y*y;}int main(){ // freopen("a.txt","r",stdin); int n,m,t,sum,count; scanf("%d",&t)