原创 51nod 1126 求遞推序列的第N項【矩陣快速冪】

#include<iostream> #include<string.h> using namespace std; const int mod=7; typedef struct node{ long long a

原创 51nod 1416 兩點 【dfs+特殊判斷】

題目來源: CodeForces 基準時間限制:1 秒 空間限制:131072 KB 分值: 20 難度:3級算法題 收藏 關注 福克斯在玩一款手機解迷遊戲,這個遊戲叫做”兩點”。基礎級別的時候是在一個n×m單元上玩

原创 luogu P1141 01迷宮【dfs記憶化】

題目描述 有一個僅由數字0與1組成的n×n格迷宮。若你位於一格0上,那麼你可以移動到相鄰4格中的某一格1上,同樣若你位於一格1上,那麼你可以移動到相鄰4格中的某一格0上。 你的任務是:對於給定的迷宮,詢問從某一格開始能移動到多

原创 51nod 1268 和爲K的組合 【dfs or dp】

dfs做法 這個dfs寫的不錯 開始我寫的運行結果是錯的,這個是某一個大神的,代碼很短 ,而且很精煉,值得學習 #include<iostream> #include<stdio.h> #include<string> #inc

原创 大數加法 以及 大數減法的思路

大數加法代碼 註釋 如下: #include<iostream> #include<ctype.h> #include<cstdio> #include<algorithm> using namespace std; #inc

原创 51nod 1014 X^2 Mod P【暴力】

#include<iostream> #include<string.h> #include<algorithm> using namespace std; int m[100000]; int main(){ int p,a; ci

原创 F.巴啦啦能量 【尺取法】

F.巴啦啦能量 Time Limit: 2500 MS Memory Limit: 256000 K Total Submit: 70 (24 users) Total Accepted: 9 (9 users) S

原创 luogu P1443 馬的遍歷 【隊列 dfs】

題目描述 有一個n*m的棋盤(1 //這是一個簡單的dfs做的 #include<iostream> #include<string.h>//memset要用到 #include<queue> #include<iomanip

原创 string find的用法詳解

/* string find()的使用 #include<iostream> #include<string> using namespace std; int main(){ string s

原创 dp之揹包總結篇

前言:揹包問題在dp中可以說是經典,作爲一個acmer,到現在才正式學習dp,可以說是比較失敗的。我個人比較認同一點,想要做一個比較成功的acmer,dp、搜索、數學必須精練,比較遺憾的是,對我我自身而言,並沒有早早的認識到這個問

原创 luogu P1101 單詞方陣【dfs】

題目描述 給一nXn的字母方陣,內可能蘊含多個“yizhong”單詞。單詞在方陣中是沿着同一方向連續擺放的。擺放可沿着8個方向的任一方向,同一單詞擺放時不再改變方向,單詞與單詞之間[color=red]可以[/color]交叉,

原创 lower_bound upper_bound 【 二分函數的使用】

lower_bound(first,last,val)表示找到第一個>=val的值的地址 upper_bound(first,last,val)表示找到第一個>val的值的地址 int pos=lower_bound(a,a+

原创 51nod 1396 還是01串 【思維題】

先記錄所有1的個數,然後通過,對每一個0的,判斷是否和後面的1相等即可 #include<iostream> #include<string> #include<string.h> using namespace std; char a

原创 51nod 1414 冰雕

用暴力枚舉 一個一個加 #include<stdio.h> int a[1000010]; int main(){ int n; scanf("%d",&n); int sum=0; for(i

原创 51nod 1092 迴文字符串 【巧用 dp】

用原串和倒置串進行匹配 統計不同的單詞的個數 該個數即爲 需要添加的 也爲 需要刪除的 #include<bits/stdc++.h> using namespace std; const int ma=1e3+10; int